0

I am using this (file here) script and i am using check all script in first row for my checkboxes. But first when I filtered for a column, this script selected checkboxes at hidden rows, too.

$(document).ready(function(){
$('#select_all').on('click',function(){
    if(this.checked){
        $('.checkbox').each(function(){
            this.checked = true;
        });
    }else{
         $('.checkbox').each(function(){
            this.checked = false;
        });
    }
});

$('.checkbox').on('click',function(){
    if($('.checkbox:checked').length == $('.checkbox').length){
        $('#select_all').prop('checked',true);
    }else{
        $('#select_all').prop('checked',false);
    }
});
});

Thanks for your helps.

3
  • can you share the relevant html code as well? Commented Sep 29, 2015 at 22:50
  • Try $('.checkbox:visible') Commented Sep 29, 2015 at 22:59
  • @Malk, this works perfectly. Thanks... Commented Sep 29, 2015 at 23:05

2 Answers 2

1

Use the jQuery :visible selector to leave out the checkboxes that have been filtered. https://api.jquery.com/visible-selector/

$('#select_all').on('click',function(){
    var doCheck = this.checked;
    $('.checkbox:visible').each(function(){
         this.checked = doCheck;
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Yeah. My new codes:

$(document).ready(function(){
$('#select_all').on('click',function(){
    if(this.checked){
        $('.checkbox:visible').each(function(){
            this.checked = true;
        });
    }else{
         $('.checkbox:visible').each(function(){
            this.checked = false;
        });
    }
});

$('.checkbox:visible').on('click',function(){
    if($('.checkbox:checked').length == $('.checkbox:visible').length){
        $('#select_all').prop('checked',true);
    }else{
        $('#select_all').prop('checked',false);
    }
});
});

Thanks everybody...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.