根据DataTables文档,使用服务器端时无法导出所有行:
关于服务器端处理的特别说明:在服务器端处理模式(
serverSide)中使用DataTables时,selector-modifier由于所有处理(排序,搜索等)均在服务器上执行,因此对所选行的影响很小。因此,客户端上唯一存在的行是任何时候表中显示的行,选择器只能选择当前页面上的行。
我通过在长度菜单中添加“ ALL”参数来解决此问题,并训练最终用户在执行PDF(或XLS)导出之前显示所有记录:
var table = $('#example').DataTable({ serverSide: true, ajax: "/your_ajax_url/", lengthMenu: [[25, 100, -1], [25, 100, "All"]], pageLength: 25, buttons: [ { extend: 'excel', text: '<span ></span> Excel Export', exportOptions: { modifier: { search: 'applied', order: 'applied' } } } ], // other options});


