简体   繁体   English

JS,如何选择服务器端DataTable的所有行数据

[英]JS, How to select all rows data of serverside DataTable

I have 2 pages of serverside Datatable and I want to select all rows data from all pages我有 2 页服务器端数据表,我想从所有页面中选择所有行数据

在此处输入图片说明

And this code而这段代码

var table = $('#table').DataTable({
    "processing": true,
    "serverSide": true,
    /*
        Some code
    */
})

var data = table.rows().data()
console.log(data)

returns the data of selected page only ( in this case the data of 1st page )仅返回所选页面的数据(在本例中为第一页的数据)

So, is it possible to select all data from all pages for serverside DataTables ?那么,是否可以从服务器端 DataTables 的所有页面中选择所有数据?

No, you can't.不,你不能。 If you use remote paging, the client doesn't know anything about other pages records yet.如果您使用远程分页,客户端还不知道其他页面记录的任何信息。

According to documentation to select all records for local paging.根据文档选择所有记录进行本地分页。 You could use你可以用

table.rows().select()

In same way, if you want to deselect them just try like this.同样,如果您想取消选择它们,请尝试这样。

table.rows().deselect();

You can simply add "All" option to lengthMenu drop-down like below code:您可以简单地将"All"选项添加到lengthMenu下拉菜单中,如下面的代码:

lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ],

显示 NN 条目

so the user can show all the data on one page, then do the filtering and search and select all the data which is needed.因此用户可以在一页上显示所有数据,然后进行过滤和搜索并选择所需的所有数据。 lengthMenu is one of the datatable properties that could be modified based on your needs. lengthMenu是可以根据您的需要修改的数据表属性之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM