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

How to check all checkboxes of a grid that are not disabled

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BitShift
Top achievements
Rank 1
Veteran
BitShift asked on 11 Jan 2021, 06:55 PM

Have a grid with a checkbox column and with a client template that includes a master checkbox.  Im able to check/uncheck all checkboxes.  However now I need to only check those that are not disabled.  Checkbox click event passes "ele" to this method checkAll.  Check/uncheck all works, but how to check first if the disabled property is set?

01.function checkAll(ele) {
02.    var state = $(ele).is(':checked');
03.    var grid = $('#MyGridList').data().kendoGrid;
04.    $.each(grid.dataSource.view(), function () {
05.       //$(".chkbx").prop("checked", state);
06. 
07.       //todo dont allow disabled lines to be selected
08.        if ($(".chkbx").prop("disabled") == false) {
09.            console.log("check checkbox");
10.        }
11.        else {
12.            console.log("dont check checkbox");
13.        }
14. 
15.    });
16. 
17.}

 

2 Answers, 1 is accepted

Sort by
0
BitShift
Top achievements
Rank 1
Veteran
answered on 11 Jan 2021, 08:39 PM

Ok, I think I got it

01.function checkAll(ele) {
02.    var state = $(ele).is(':checked');
03.    var grid = $('#MyGridList').data().kendoGrid;
04.    $.each(grid.dataSource.view(), function (indx,row) {
05.        if ($(".chkbx").eq(indx).prop("disabled") == false) {
06.            console.log("enabled checkbox");
07.            $(".chkbx").eq(indx)..prop("checked", state);
08.        }
09.        else {
10.            console.log("disabled checkbox");
11.        }
12.         
13.         
14.    });
15. 
16.}
0
Neli
Telerik team
answered on 13 Jan 2021, 02:16 PM

Hi Randal,

As far as I understand, you have managed to resolve the issue by yourself. I am happy to hear that. Thank you also for sharing your solution with the community. I am sure it will be helpful to the other users in the future.

Another possibility to find the checkboxes that are not disabled is to use the 'k-state-disabled' class. Below is an example:

$.each($('td:not(.k-state-disabled) .k-checkbox'), function () {			 
	$(this).prop("checked", true)	 
});

Here is a Dojo example where all the checkboxes that are not disabled could be checked on a button click.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
BitShift
Top achievements
Rank 1
Veteran
Answers by
BitShift
Top achievements
Rank 1
Veteran
Neli
Telerik team
Share this question
or