admin管理员组

文章数量:1336367

I have a DataTables with server side processing. On server side I have functions retrieving filters from the ajax request and fetching data from database.

Now I want export data into excel file with filters.

I assume I have to design an excel file creator on server side and send the file through HTTP response.

I would like use already-defined functions to handle export request.

My question is: how can I send DataTables filter as same format as in the ajax request to my server ?

I have a DataTables with server side processing. On server side I have functions retrieving filters from the ajax request and fetching data from database.

Now I want export data into excel file with filters.

I assume I have to design an excel file creator on server side and send the file through HTTP response.

I would like use already-defined functions to handle export request.

My question is: how can I send DataTables filter as same format as in the ajax request to my server ?

Share Improve this question asked Aug 14, 2015 at 15:36 ZxcvZxcv 1,7472 gold badges16 silver badges23 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

SOLUTION

You can use ajax.params() to get the data submitted by DataTables to the server in the last Ajax request.

Then you can redirect to script that generates Excel file with these parameters using jQuery helper function $.param that converts array into query string.

For example:

window.location = '/getFile.php?' + $.param($('#example').DataTable().ajax.params());

where example is table ID.

NOTES

There is also TableTools extension with Download button but with recent jQuery DataTables 1.10.8 release, TableTools extension is now deprecated.

本文标签: javascriptServer side excel export with DataTableStack Overflow