jmvtrinidad
jmvtrinidad

Reputation: 3658

jQuery DataTables - Access all rows data

I'm using jQuery DataTables and want to copy all rows (save in JavaScript array) upon clicking the header checkbox.

First Page

I want to find where jQuery DataTables store the HTML for remaining page of rows, so I can navigate through JavaScript then check it there or set property checked to true.

Something like this one.

enter image description here

Other information:

Upvotes: 23

Views: 77552

Answers (5)

shmengie
shmengie

Reputation: 63

Set the pageLength:

$('#example').dataTable( {
  "pageLength": 50
} );

Upvotes: 0

FOD
FOD

Reputation: 107

Using

tableObject.rows().data() 

will return all the data from the table.

Upvotes: 1

Vineela Thonupunuri
Vineela Thonupunuri

Reputation: 591

If you do this:

$('#table').DataTable().rows().data(); 

you get a lot of unnecessary data.

If you just want the table data you can do this:

$('#table').DataTable().rows().data().toArray();

Upvotes: 17

jmvtrinidad
jmvtrinidad

Reputation: 3658

I find the generated element by jQuery DataTables using this code, and I can copy the whole tr element that hides when paging the DataTables.

$('#example').DataTable().rows().iterator('row', function(context, index){
    var node = $(this.row(index).node()); 
    //node.context is element of tr generated by jQuery DataTables.
});

Upvotes: 15

Gyrocode.com
Gyrocode.com

Reputation: 58870

SOLUTION

There are many methods that could be used for that purpose. You can use rows().data() to get the data for the selected rows.

Example:

var table = $('#example').DataTable();

var data = table
    .rows()
    .data();

alert( 'The table has ' + data.length + ' records' );

DEMO

See this jsFiddle for code and demonstration.

Upvotes: 20

Related Questions