This is a migrated thread and some comments may be shown as answers.

[Solved] Check all checkboxes in Grid

3 Answers 215 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
leo
Top achievements
Rank 1
leo asked on 11 Jul 2011, 09:24 PM
Hello, I hope someone can provide me a solution for my problem ... I have a grid with checkboxes in one column. In the header of this column I have also a checkbox. What i want is when i check or uncheck this checkbox it will change the checked state of all the checkboxes of the column. Can someone please provide me the jquery script for that ? I am new to jquery and telerik ... Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Felipe
Top achievements
Rank 1
answered on 16 May 2012, 12:09 AM
Friend you could solve your problem, I have the same error 
0
Pechka
Top achievements
Rank 1
answered on 16 May 2012, 07:44 AM
Find a way to select that master checkbox and execute the following in its click handler

$('#masterCheckbox').click(function(){
if($(this).is(':checked')){
$(':checkbox').attr('checked','checked') // you can also search for checkboxes with the Grid as context 
}
else{
$(':checkbox').removeAttr('checked')  
}
})
 
0
Greg
Top achievements
Rank 1
answered on 16 May 2012, 07:41 PM
Add this to top of grid preferably in a div tag.

<
input  id='checkAll' type='checkbox' /> Check All</span>

Add check box to grid, then add a class to it called "check-box"

Add this jQuery to a script tag at bottom of page: Grid id is 'Grid' in this example, you should change it to yours if different
$(document).ready(function () {
    $('#checkAll').click(function () {
        if ($(this).attr('checked')) {
            $('.check-box').attr('checked', 'checked');
        } else {
            $('.check-box').removeAttr('checked');
        }
    });
 
    $('#Grid input[type=checkbox][id!=checkAll]').click(function () {
        var numChkBoxes = $('#Grid input[type=checkbox][id!=checkAll]').length;
        var numChkBoxesChecked = $('#Grid input[type=checkbox][checked][id!=checkAll]').length;
        if (numChkBoxes == numChkBoxesChecked && numChkBoxes > 0) {
            $('#checkAll').attr('checked', 'checked');
        }
        else {
            $('#checkAll').attr('checked', '');
        }
    });
});
 

That should check and uncheck all check boxes in a grid
Tags
Grid
Asked by
leo
Top achievements
Rank 1
Answers by
Felipe
Top achievements
Rank 1
Pechka
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Share this question
or