0

I am using ngCsv to try and export data to CSV. After clicking a button, I download all required data after which I would like to export it to CSV. However, I am getting a blank CSV for some reason. Below is the code for the button:

<button class="btn-primary" type="button" ng-csv="getAllData()" csv-header="['Order Number', 'Handling Code', 'Expected Date', 'Status', 'Reference', 'Loading Date', 'Unloading Date', 'Transaction Status']" filename="test.csv">Export to CSV</button>

The method I use to download the data:

$scope.getAllData = function () {
            return ordersService.getAllOrders()
                .success(function (data) {                        
                    return data.Items;
                })
        };

The getAllOrders method:

service.getAllOrders = function () {
    return $http.get(ordersApiBase);
};

I've tried varoius other ways as can be seen here: Using ngCsv with an external API and here: https://github.com/asafdav/ng-csv/issues/58 yet I can't seem to figure out what I am doing wrong. Has anyone done something similar before?

3
  • Might be the problem with the return data. Can you console.log(data.Items)? And post the result? Commented Jan 21, 2016 at 14:21
  • I have checked this and it returns the full list of objects: , Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object…] [0 … 99] 0: Object ExpectedDate: "12/3/2015 12:00:00 AM" HandlingCode: "i" OrderNumber: "8500000007193" Reference: "PO-106993" Commented Jan 22, 2016 at 7:05
  • Currently, ng-csv is not supporting nested objects. Commented Jan 22, 2016 at 12:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.