[英]Kendo UI Grid - Custom command button disabled depending on boolean property
How can I set the class to disabled for a custom command on a Kendo grid depending on the boolean value of a property? 如何根据属性的布尔值将Kendo网格上的自定义命令的类设置为禁用?
I want to use this approach to make the button disabled: https://docs.telerik.com/kendo-ui/knowledge-base/disable-the-grid-command-buttons 我想使用这种方法来禁用按钮: https : //docs.telerik.com/kendo-ui/knowledge-base/disable-the-grid-command-buttons
Javascript: 使用Javascript:
{ command: { name: "custom", text: "Exclude", click: excludeCategorization }, title: " ", width: "60px" }
I want to add a condition like this using the property IsEnabled
but if possible using the k-state-disabled
class 我想使用属性IsEnabled
添加这样的条件,但如果可能的话,使用k-state-disabled
类
#= IsEnabled ? disabled="disabled" : "" #
I don't believe you can assign classes conditionally through a template, however you can use the dataBound event to crawl through the rows and manipulate the classes. 我不相信您可以通过模板有条件地分配类,但是您可以使用dataBound事件来爬行行并操纵类。 I would start with all of them disabled and then enable the ones that need to be active, but you can build your own logic. 我将从禁用所有选项开始,然后启用需要激活的选项,但是您可以构建自己的逻辑。 Here's an example: 这是一个例子:
<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>
Here's a link to a Dojo: https://dojo.telerik.com/ubuneWOB 这是Dojo的链接: https : //dojo.telerik.com/ubuneWOB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.