Ayan
Ayan

Reputation: 545

AngularJS ng-grid Export to Excel for selectedItems

We have a ng-grid which displays data retrieved from a rest service. I want to export the rows selected by user(ng-grid selection check box enabled) to an excel and open that excel. The current behavior of app is Export to excel button calling a rest service with selected items from ng-grid and using POI to put the data into excel and returning the excel.

Is there a better way to do this? The data is already in browser, is there any angularjs, jQuery or javascript function to do this?

Upvotes: 3

Views: 14383

Answers (1)

AardVark71
AardVark71

Reputation: 4126

There is a plugin for csv export : https://github.com/angular-ui/ng-grid/tree/master/plugins

It can be easily added by adding it to your gridoptions, while making sure to display the footer.

 $scope.gridOptions = {
        data: ...,
        plugins: [new ngGridCsvExportPlugin()],
        showFooter: true,
        ...
      };

It exports all your records from your specified grid.data.

[Although you can pass in an options object for specifying columns etc. there isn't an option currently to limit to selectedItems.]

It looks easy though to adjust the ng-grid-csv-export.js source to loop over grid.mySelections instead over grid.data. (not tested by me yet)

Upvotes: 5

Related Questions