asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
572 stars 216 forks source link

JSON/JS array format #200

Open ORESoftware opened 7 years ago

ORESoftware commented 7 years ago

Looking forward to using this module!

What's missing in the docs (IMO) is the format of the array - there are several different potential array formats.

I can try to figure this out, but it would best if this were explicitly stated, all we need is a couple elements in the array and we will get the idea so it should fit easily in the README.md file, thx

ORESoftware commented 7 years ago

in other words, I am looking for:

 $scope.getArray = function(){

      return [];  // what format is the array supposed to have? :)

    };
ORESoftware commented 7 years ago

so I tried this:

   $scope.getArray = function () {

      return [
        {
          a: 'b',
          c: 'd',
          x: 'e'
        },
        {
          a: 'v',
          c: 'r',
          x: 't'
        }];

    };

and I basically get:

b,d,e
v,r,t

so that seems to work, but I wish the headers would be inferred

davidamitchell commented 7 years ago

if you use the csv-label directive then the keys will be the header row of the csv file.

csv-label: Defines whether or not using keys as csv column value (default is false).