Select all checkboxes in current page

Select all checkboxes in current page

swamyveeraswamyveera Posts: 4Questions: 0Answers: 0
edited July 2013 in DataTables 1.9
Hi there,

This is my code
[code]
var oTable=$("table#da-list").dataTable({
sPaginationType: "full_numbers",
"bStateSave": true,
"aoColumns":[
{"bSortable":false},
null,null,null,null,
{"bSortable":false}

]
});
var nodes=oTable.fnGetNodes();
$("#checkbox-main-header").click(function(){
if($(this).is(":checked")){
$('.checkbox-tr',nodes).attr("checked",true);
}else{
$('.checkbox-tr',nodes).attr("checked",false);
}
});
[/code]
But this modifies checkboxes in all pages. How can i select only the ones in the current page?

Thanks

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Don't use fnGetNodes if you just want the visible nodes. Just use:

    [code]
    $('.checkbox-tr').attr("checked",true);
    [/code]

    Allan
  • swamyveeraswamyveera Posts: 4Questions: 0Answers: 0
    Thanks allan. I guess i was thinking over the board and missing on smaller details.

    That worked!
  • swamyveeraswamyveera Posts: 4Questions: 0Answers: 0
    But that added a tricky situation,

    My "select all" check box is in the header.
    So when i check it, all the checkboxes in the current page are selected.
    But, when i move to the next page, the "select all" checkbox is still checked.
    Any quick way to sort this out?
This discussion has been closed.