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

Loop through swiches in grid

1 Answer 142 Views
Switch
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 15 Oct 2020, 07:38 PM

I'm having trouble accessing switches in a grid column.  I want to loop through them and toggle them on after clicking a toolbar button.

The click event is working.  But getting 'undefined' on 'switchInstance ':

 

Column with switches code:

.Columns(columns =>
        {

         columns.Bound(p => p.Exempt).Width(100).Filterable(ftb => ftb.Multi(true)).Sortable(false).ClientTemplate(
                "<input class='exemptSwitch' id='exemptSwitch' \\#if (Exempt) { \\# checked='checked' \\# } \\# type='checkbox' />");

})

 

Toolbar button code:

.ToolBar(toolBar =>
        {
            toolBar.Custom()
                .Name("EnableAllFiltered")
                .Text("Enable All Filtered")
                .IconClass("k-icon k-i-play")
                ;

 })

 

Click event code:

$(function () {
    $(".k-grid-ExemptAllFiltered", "#SubscriberGrid").on("click", function (e) {   <--- click of custom grid header toolbar button

         $("#SubscriberGrid .exemptSwitch").each(function () {
               var switchInstance = $(this).data("kendoSwitch");
               switchInstance.enable(true);
          });

});

 

Any assistance would be greatly appreciated!

 

Jon

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 20 Oct 2020, 12:42 PM

Hi Jon,

I have investigated the provided code snippets and I have noticed that within the ClientTemplate of the column, you have specified an input with an ID "exemptSwitch". However, within the click handler, you are trying to access it via the ".exemptySwitch" selector that searches for elements with class "exemptSwitch".

Can you try switching the id to class and see if that makes a difference?

 

Kind regards,
Tsvetomir
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
Switch
Asked by
Jon
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or