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

How to check and uncheck all checkboxes in grid

2 Answers 3488 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BitShift
Top achievements
Rank 1
Veteran
BitShift asked on 25 Nov 2020, 10:34 PM

Im trying to add a feature to an existing app that is using a rather dated Kendo version 2015.3.1111
I need to add a checkbox that when clicked will check or uncheck all checkboxes in the rows.  I'm aware of a newer feature in the 2017+ libraries, but for now we can't update this app.  So with jQuery, Ive looked at several examples, but its all over the place. Help? Examples?
My client and header template

 

columns.Template(@<text></text>).ClientTemplate("<input type='checkbox' id='gridCheckbox'  onclick='handleClick(this);' value='#= LineItemId #'  #= Selected ? 'checked':'' # class='chkbx' />")
           .HeaderTemplate("<input type='checkbox' id='masterCheckBox' onclick='checkAll(this)'/>").Width(50);

 

 


2 Answers, 1 is accepted

Sort by
0
BitShift
Top achievements
Rank 1
Veteran
answered on 25 Nov 2020, 11:04 PM

Not sure if this is the best way or not, but I managed to figure out now

check and un-check all works.  The key line is
$(".chkbx").prop("checked", state);

 

function checkAll(ele) {
    var state = $(ele).is(':checked');
    var grid = $('#StopList').data().kendoGrid;
    $.each(grid.dataSource.view(), function () {
        if (this['Selected'] != state) {
            this.dirty = true;
        }
        this['Selected'] = state;
         
        $(".chkbx").prop("checked", state);
    });
    //grid.refresh();
}

 

 

0
Anton Mironov
Telerik team
answered on 27 Nov 2020, 10:45 AM

Hello Randel,

Thank you for sharing the approach with the team. This is the recommended way to achieve the desired behavior.

As the issue you were facing is resolved, I will close this ticket thread now.

If future assistance is needed do not hesitate to contact me or the team opening a new ticket.

 

Kind Regards,
Anton Mironov
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
Anton Mironov
Telerik team
Share this question
or