asafdav / ng-csv

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

Unable to set column order #161

Closed sarfarazansari closed 8 years ago

sarfarazansari commented 8 years ago

Hey, I am unable to set column order here is my snippet. <button class="btn btn-success" ng-csv="csvData" csv-header="getCSVHeader()" filename="{{ searchFormData.group.name }}.csv" field-separator="," decimal-separator="." csv-column-order="order">Download CSV</button>

here is the javascript code I am using coffee `$scope.getCSVHeader=()-> return ["CR Total", "DR Total", "Opening Bal.", "Closing Bal.", "Uniquename", "Name", "Parent", "Closing Bal. Type", "Opening Bal. Type"]

$scope.order = ["Name","Opening Bal.", "Closing Bal.", "CR Total", "DR Total", "Parent", "Uniquename", "Closing Bal. Type", "Opening Bal. Type"]`

In result am getting a blank CSV file. If I remove csv-column-header attribute then It will generate proper file.

Please let me know what am doing wrong.

And one more feature request I have It will not take a nested object while generating CSV for example

If I have var data = { name: "Name" uniqueName: "uniqueName" closingBalance: { amount: 500 type: "DEBIT" } } then it will generate file with [object object] contains in cell.

I have to make it flatten object like below then it will generate perfect. var data = { name: "Name" uniqueName: "uniqueName" closingBalanceAmount: 500 closingBalanceType: "DEBIT" }

Thanks

sarfarazansari commented 8 years ago

Hi sorry actually problem is in my order object here is the snippet $scope.order = [ "name" "closingBalance" "closeBalType" "openingBalance" "openBalType" "creditTotal" "debitTotal" "uniqueName" ]