jquery – 如何使用Ajax从Datatables导出所有行?

前端之家收集整理的这篇文章主要介绍了jquery – 如何使用Ajax从Datatables导出所有行?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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) the selector-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
});

猜你在找的jQuery相关文章