【问题标题】:Kendo Grid Core - Loop through switches in gridKendo Grid Core - 循环通过网格中的开关
【发布时间】:2021-01-30 08:45:39
【问题描述】:

我无法访问网格列中的开关。我想循环浏览它们并在单击工具栏按钮后将它们打开。

点击事件正在工作。但是在“switchInstance”上得到“未定义”:

网格列:

.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(toolBar =>
 {
      toolBar.Custom()
       .Name("EnableAllFiltered")
       .Text("Enable All Filtered")
       .IconClass("k-icon k-i-play")
       ;
 })

点击事件:

$(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.check(true);
         });
});

任何帮助将不胜感激!

乔恩

【问题讨论】:

    标签: asp.net asp.net-core kendo-ui telerik kendo-grid


    【解决方案1】:

    看起来这个匿名函数没有在 Kendo Grid 事件中调用。

    尝试这样的操作来查看您的this 在控制台中是什么:

    $(function () {
        $(".k-grid-ExemptAllFiltered", "#SubscriberGrid").on("click", function (e) {   //click of custom grid header toolbar button
    
             $("#SubscriberGrid .exemptSwitch").each(function () {
                   console.log(this);
                   // var switchInstance = $(this).data("kendoSwitch");
                   // switchInstance.check(true);
             });
    });
    

    如果您知道自己一直想要来自 Kendo Grid 的数据,请尝试以下操作:

    $(function () {
        $(".k-grid-ExemptAllFiltered", "#SubscriberGrid").on("click", function (e) {   //click of custom grid header toolbar button
    
             $("#SubscriberGrid .exemptSwitch").each(function () {
                   var grid = $('#SubscriberGrid').data('kendoGrid');
                   console.log(grid);
                   var switchInstance = grid.data("kendoSwitch");
                   switchInstance.check(true);
             });
    });
    

    我不知道你的程序的结构,所以可能不对。

    另一种选择是提供事件项e,如下所示:

    $(function () {
        $(".k-grid-ExemptAllFiltered", "#SubscriberGrid").on("click", function (e) {   //click of custom grid header toolbar button
    
             $("#SubscriberGrid .exemptSwitch").each(function (e) { // notice the 'e'
                   var grid = e.sender;
                   console.log(grid);
                   var switchInstance = grid.data("kendoSwitch");
                   switchInstance.check(true);
             });
    });
    

    我不知道这是否有帮助。我也是 Kendo Grid 的新手,我只是提供一些我看到的技巧。

    如果有帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多