如何使用 Ajax 从数据表中导出所有行? [英] How to export all rows from Datatables using Ajax?

查看:23
本文介绍了如何使用 Ajax 从数据表中导出所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表中的新功能:HTML5 导出按钮".我正在使用 Ajax 加载数据.

I am using new feature in Datatables: "HTML5 export buttons". I am loading data with Ajax.

https://datatables.net/extensions/buttons/examples/html5/简单的.html

问题是它只导出当前显示的页面.

The problem is that it only export the page that is currently displayed.

我是这样导出的:

buttons: [
    {
        extend: 'pdfHtml5',
        text: 'PDF',
        exportOptions: {
            "columns": ':visible',
        }
    },
]

如何导出所有行?

推荐答案

根据 DataTables 文档 使用服务器端时无法导出所有行:

According to DataTables documentation there is no way to export all rows when you are using server side:

关于服务器端处理的特别说明:在服务器端处理模式 (serverSide) 下使用 DataTables 时,selector-modifier 对所选行的影响很小,因为所有处理(排序、搜索等)都在服务器上执行.因此,客户端唯一存在的行是表中任何时候显示的行,选择器只能选择当前页面上的行.

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)导出之前显示所有记录来解决此问题:

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 从数据表中导出所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆