ArmKh
ArmKh

Reputation: 445

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

enter image description here

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 ?

Upvotes: 2

Views: 2491

Answers (2)

Hamid Ghasemi
Hamid Ghasemi

Reputation: 1

You can simply add "All" option to lengthMenu drop-down like below code:

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

show NN entries

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.

Upvotes: 0

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

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();

Upvotes: 1

Related Questions