繁体   English   中英

Kendo UI Grid-根据布尔属性禁用了自定义命令按钮

[英]Kendo UI Grid - Custom command button disabled depending on boolean property

如何根据属性的布尔值将Kendo网格上的自定义命令的类设置为禁用?

我想使用这种方法来禁用按钮: https : //docs.telerik.com/kendo-ui/knowledge-base/disable-the-grid-command-buttons

使用Javascript:

{ command: { name: "custom", text: "Exclude", click: excludeCategorization }, title: " ", width: "60px" }

我想使用属性IsEnabled添加这样的条件,但如果可能的话,使用k-state-disabled

#= IsEnabled ? disabled="disabled" : "" # 

我不相信您可以通过模板有条件地分配类,但是您可以使用dataBound事件来爬行行并操纵类。 我将从禁用所有选项开始,然后启用需要激活的选项,但是您可以构建自己的逻辑。 这是一个例子:

<div id="grid"></div>
<script>
  var grid;
  $("#grid").kendoGrid({
    dataBound:function(e){
      var grid = $("#grid").data("kendoGrid");
      var items = e.sender.items();
      items.each(function (index) {
        var dataItem = grid.dataItem(this);
        $("tr[data-uid='" + dataItem.uid + "']").find(".excludeCategorization").each(function( index ) {
          if(dataItem.isEnabled)
             {
                $(this).removeClass('k-state-disabled')   
             }
        });
      })
    },
    columns: [
      { field: "name" },
      { field: "enabled" },
      { command: [{ className: "k-state-disabled excludeCategorization", name: "destroy", text: "Remove" },{ className: "k-state-disabled", name: "edit", text: "Edit" }] }
    ],
    editable: true,
    dataSource: [ { name: "Jane Doe", isEnabled: false },{ name: "John Smith", isEnabled: true } ]
  });
</script>

这是Dojo的链接: https : //dojo.telerik.com/ubuneWOB

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM