Reputation: 6790
I cant get this checkbox to check the checkboxs which are not hidden
Basiclly I need it to not check any check box in the table which is hidden from view
ui-tableFilter-hidden
$("input:checkbox.checkall").live('click', function(event){
var checkedStatus = this.checked;
if(!$('table tbody tr').hasClass('ui-tableFilter-hidden'))
{
$("td.small input:checkbox").each(function() {
this.checked = checkedStatus;
});
}
});
Quick fix was to replace the above code with this one
$("input:checkbox.checkall").live('click', function(event){
var checkedStatus = this.checked;
$("td.small input[type=checkbox]:visible").each(function() {
this.checked = checkedStatus;
});
});
Upvotes: 0
Views: 954
Reputation: 477
Ideally, you should be using the change event, since inputs can be altered with more than just clicks. You can also just find all rows with the ui-tableFilter-hidden
, then check the appropriate checkboxes. I also use prop
to identify the checked state of the box, available as of jQuery 1.6, although this.checked
should work as well.
$("input:checkbox.checkall").change(function(){
var jCheckAll = $(this);
var checkedStatus = jCheckAll.prop("checked");
var jRows = $('table tbody tr:not(.ui-tableFilter-hidden)');
jRows.find("td.small input:checkbox").prop("checked",checkedStatus);
});
Upvotes: 0
Reputation: 7947
Your IF check and the EACH loop are unrelated in the code above. The IF will evaluate to true at some point and then the EACH loop will iterate through all checkboxes matching the selector, regardless of what you checked in the IF.
Try something like this instead...
$('table tbody tr')each(function(){
if(!$(this).hasClass('ui-tableFilter-hidden')){
$(this).find("td.small input:checkbox").each(function() {
this.checked = checkedStatus;
});
}
}
Upvotes: 1