如何使用Ajax从Datatables导出所有行? [英] How to export all rows from Datatables using Ajax?
问题描述
我在Datatables中使用新功能:HTML5导出按钮。我正在使用Ajax加载数据。
https:// datatables.net/extensions/buttons/examples/html5/simple.html
问题是它只导出当前显示的页面。 p>
我正在这样导出:
按钮:[
{
extends:'pdfHtml5',
text:'PDF',
exportOptions:{
columns:':visible',
}
}
]
如何导出所有行?
根据 DataTables文档当您使用服务器端时,无法导出所有行:
服务器上的特别注意事项边处理:在服务器端处理时使用DataTable模式(
serverSide
)selector-modifier
对所有处理(排序,搜索等)所选择的行几乎没有影响)在服务器上执行。因此,客户端上唯一存在的行是在任何一个时间在表中显示的行,选择器只能选择当前页面上的那些行。
我通过在长度菜单中添加一个ALL参数,并训练最终用户在进行PDF(或XLS)导出之前显示所有记录:
var table = $('#example')。DataTable({
serverSide:true,
ajax:/ your_ajax_url / ,
lengthMenu:[[25,100,-1],[25,100,全部]],
pageLength:25,
按钮:[
{
extends:'excel',
text:'< span class =fa fa-file-excel-o>< / span> Excel Export',
exportOptions:{
修饰符:{
search:'applied',
order:'applied'
}
}
}
],
// other opti ons
});
I am using new feature in Datatables: "HTML5 export buttons". I am loading data with Ajax.
https://datatables.net/extensions/buttons/examples/html5/simple.html
The problem is that it only export the page that is currently displayed.
I am exporting like this:
buttons: [
{
extend: 'pdfHtml5',
text: 'PDF',
exportOptions: {
"columns": ':visible',
}
},
]
How can I export all rows?
According to DataTables documentation there is no way to export all rows when you are using server side:
Special note on server-side processing: When using DataTables in server-side processing mode (
serverSide
) theselector-modifier
has very little effect on the rows selected since all processing (ordering, search etc) is performed at the server. Therefore, the only rows that exist on the client-side are those shown in the table at any one time, and the selector can only select those rows which are on the current page.
I worked this around by adding an 'ALL' parameter to the length menu and training end users to display all records before doing a PDF (or XLS) export:
var table = $('#example').DataTable({
serverSide: true,
ajax: "/your_ajax_url/",
lengthMenu: [[25, 100, -1], [25, 100, "All"]],
pageLength: 25,
buttons: [
{
extend: 'excel',
text: '<span class="fa fa-file-excel-o"></span> Excel Export',
exportOptions: {
modifier: {
search: 'applied',
order: 'applied'
}
}
}
],
// other options
});
这篇关于如何使用Ajax从Datatables导出所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!