3

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?

Ayan
  • 515
  • 4
  • 9
  • 20

1 Answers1

5

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)

AardVark71
  • 3,928
  • 2
  • 30
  • 50
  • Looks easy to change the data to grid.mySelections, will try it. but How should I move that csv data to excel now in javaScript. – Ayan Oct 09 '13 at 13:50
  • You can copy text to the user's clipboard and ask user to paste it in Excel. The values should be tab delimited. – lostpacket Oct 10 '13 at 21:26
  • The link is not available now. can you provide needed help? – sms Sep 11 '14 at 10:00
  • 1
    @sms the plugin is still available on some of forked repos. Such as this one : https://github.com/choroshin/ng-grid/tree/master/plugins – AardVark71 Sep 11 '14 at 12:14