我在Datatables中使用新功能:“
HTML5导出按钮”.我正在使用Ajax加载数据.
https://datatables.net/extensions/buttons/examples/html5/simple.html
我正在出口这样:
buttons: [ { extend: 'pdfHtml5',text: 'PDF',exportOptions: { "columns": ':visible',} },]
如何导出所有行?
解决方法
根据
DataTables documentation,当您使用服务器端时,无法导出所有行:
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.
我通过在长度菜单中添加一个“ALL”参数来进行操作,并训练最终用户在执行PDF(或XLS)导出之前显示所有记录:
var table = $('#example').DataTable({ serverSide: true,ajax: "/your_ajax_url/",lengthMenu: [[25,100,-1],[25,"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 });