checkbox - Select checkboxes all only works once?
checkbox - Select checkboxes all only works once?
Im using a checkbox in the table header to select (or unselect) all checkboxes in that column. Im new to JQuery.
Code in script (Run from inside $(document).ready(function() {)....
$('#check_all').click( function() {
$('input', oTable.fnGetNodes()).attr('checked',this.checked);
} );
This code works perfectly but only once! I can click it and select all AND then i can click it and it will unselect all. However from then on i click it and nothing happens.
When i chuck a console.log("Check event hit"); into the script it fires every time.. yet it only updates the checkboxes for the first check and uncheck operations.
Any thoughts?
Matt
Code in script (Run from inside $(document).ready(function() {)....
$('#check_all').click( function() {
$('input', oTable.fnGetNodes()).attr('checked',this.checked);
} );
This code works perfectly but only once! I can click it and select all AND then i can click it and it will unselect all. However from then on i click it and nothing happens.
When i chuck a console.log("Check event hit"); into the script it fires every time.. yet it only updates the checkboxes for the first check and uncheck operations.
Any thoughts?
Matt
This discussion has been closed.
Replies
Allan
Gold. Working perfectly now.
Thanks for the tip, I got the statement based on attr from a comment you had made earlier about selecting all. I must have not got the context right.
Thanks again and great work on data tables!
Matt
More likely I got it wrong, or it was an old comment before the jQuery split between attr and prop. Either way, good to hear it is working now.
Allan
I think it was before the JQuery split! im learning!
I dont quite have a working solution as my checkbox looks to select too much!
Im using oTable.fnFilter( tTag,'5');
To filter the data but the "select all" checkbox selects items that are currently filtered out?
Is there anyway to align fnGetNodes() with what is actually on the screen?
Thanks again for your help so far!
Was this:
$('input', oTable.fnGetNodes()).prop('checked',this.checked);
used a line ive seen elsewhere: .$('tr', {"filter": "applied"} );
but this:
$('input', .$('tr', {"filter": "applied"} )).prop('checked',this.checked);
fails with "Unexpected identifier "
For reference:
$('input', oTable.$('tr', {"filter": "applied"} )).prop('checked',this.checked);
Got me going.
Matt