23

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:

  • I use data from an ajax source(serverside:false), all data is returned.
  • When I click page 1, all the rows remain Checked.

5 Answers 5

20

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Its also a nice way to access the data in jQuery DataTables, but i want the generated html by jQuery DataTables.., I found it in my answer.., Anyway Thanks!
You can also use table.rows().nodes().to$() to get jQuery collection of all row nodes. You can iterate this collection later and get the HTML for each row. See to$() for more information.
Thanks for this short answer, if you post your edited answer, I will mark it as a solution.
@janmvtrinidad, if you need nodes and their HTML content, your answer is better. You can accept your own answer as well.
@RameshPareek, use table.columns(0).data() then.
|
17

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

Comments

15

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.
});

2 Comments

how can I make this iterate through every column of the row and compare it with same column of the previous row?
basically you can access the previous row by having -1 from $(this.row(index - 1).node()). you can compare from result
1

Using

tableObject.rows().data() 

will return all the data from the table.

Comments

0

Set the pageLength:

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.