Select all filtered rows doesn't work

Select all filtered rows doesn't work

fansiskfansisk Posts: 4Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
Hi all. I tried writing a function that will be executed by a 'Select All' checkbox, and it will select all checkboxes of the current filtered rows. Every row has a checkbox among other columns.
This code works but it checks all the checkboxed of all rows, not only the filtered ones.

var myTable = $('#test_table').dataTable();
$('input', myTable.fnGetNodes()).attr('checked', obj.checked);


but if i write
var myTable = $('#test_table').dataTable();
var filteredRows= myTable._('tr', {"filter": "applied"});
$('input', filteredRows).attr('checked', obj.checked);

it doesn't do anything. Can anyone tell me why it doesn't work, or point me to a better solution to achieve my goal?

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Because `_` gets the data for the rows, not the nodes. You'd be better writing:

    [code]
    $('#test_table').dataTable().$('tr input', {filter:'applied'}).prop( 'checked', obj.checked);
    [/code]

    Allan
  • fansiskfansisk Posts: 4Questions: 0Answers: 0
    I am sorry Allan, but your code doesn't work... It doesn't select any of the checkboxes of the filtered rows...
  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Oops - try this perhaps?:

    [code]
    $('#test_table').dataTable().$('input', {filter:'applied'}).prop( 'checked', obj.checked);
    [/code]

    If not that then console.log some of the results and see what is what.

    Allan
  • fansiskfansisk Posts: 4Questions: 0Answers: 0
    Thanks Allan, your second suggestion works just fine.

    I think it would be very good, if you write this code somewhere that everyone can see it, because as i was looking for that solution, i saw a lot of posts relating to that, unanswered...

    But, great work. Thanks again
  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Usage guide on this site, and the site in general is going to get an upgrade soon. I'll be sure to include this kind of information.

    Allan
  • fansiskfansisk Posts: 4Questions: 0Answers: 0
    One last question, this code only works with version 1.9.x or with 1.8.x as well?
This discussion has been closed.