react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

Is there a way to get data from server while exporting to CSV?

Open kchaitanya89 opened this issue 8 years ago • 2 comments

Hey,

I was going through http://allenfang.github.io/react-bootstrap-table/example.html#remote "Remote Exporting CSV" example and was wondering if there is a way to get data from the server in "onExportToCSV" method? The example shows a synchronous function which expects all the data to be present in the state before callling onExportToCSV. What if I don't want to load all the data ahead of time but want to get the data only when 'export to CSV' is clicked?

Any help is appreciated.

kchaitanya89 avatar Jan 23 '17 23:01 kchaitanya89

if there is a way to get data from the server in "onExportToCSV" method?

react-bootstrap-table does not support api for fetching data from server, but you can use your favor lib to do it in onExportToCSV function.

The example shows a synchronous function which expects all the data to be present in the state before callling onExportToCSV. What if I don't want to load all the data ahead of time but want to get the data only when 'export to CSV' is clicked?

that's a good question, I think it is not very well for async call, particular on this function, I'll find some solution, thanks

AllenFang avatar Jan 24 '17 01:01 AllenFang

Yes, there is a way around the library by using callbacks

  1. Create an exportCSVBtn

  2. Change the handleExportCSVButtonClick method to fetch data using a callback and update the state of the table

  3. Use the following method to export the rendered table thisApp.refs.table.handleExportCSV()

  4. Don't foget to remove the onClick method being called

Let me know if you run in to any problems

nyzszn avatar Mar 08 '19 13:03 nyzszn