服务器端excel导出与DataTable [英] Server side excel export with DataTable
问题描述
在服务器端,我有功能从ajax请求中检索过滤器,并从数据库中提取数据。
现在我要将数据导出到具有过滤器的Excel文件中。 p>
我假设我必须在服务器端设计一个excel文件创建者,并通过HTTP响应发送文件。
I想要使用已定义的函数来处理导出请求。
我的问题是:如何将数据表过滤器与在我的服务器的ajax请求中一样的格式发送? / p>
解决方案
您可以使用 ajax.params()
将数据表提交给最后一个Ajax请求中的服务器。
然后您可以使用jQuery帮助函数重定向到使用这些参数生成Excel文件的脚本 $。param
将数组转换成查询字符串。
例如:
window.location ='/getFile.php?'+ $ .param $('#example')。DataTable().ajax.params());
其中示例
是表ID。 p>
注意
还有TableTools扩展名,其中包含下载按钮,但是最近的jQuery DataTables 1.10.8现在不推荐使用TableTools扩展。
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 ?
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.
这篇关于服务器端excel导出与DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!