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?

1
  • Maybe this topic can help Commented Oct 9, 2013 at 6:57

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

4 Comments

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.
You can copy text to the user's clipboard and ask user to paste it in Excel. The values should be tab delimited.
The link is not available now. can you provide needed help?
@sms the plugin is still available on some of forked repos. Such as this one : github.com/choroshin/ng-grid/tree/master/plugins

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.