gpt4 book ai didi

c# - 通过 kendogrid 中的数据条件禁用命令

转载 作者:行者123 更新时间:2023-11-30 12:23:24 26 4
gpt4 key购买 nike

如何通过给定的 bool 值禁用行上的删除按钮?

给定这个示例模型:

public class Example
{
public bool CanDeleted {get; set;} //Delete Button only if true
//...
}

KendoGrid<Example> :

columns.Command(c => c.Destroy()); //I want something something like m => m.CanDeleted

最佳答案

感谢@Eldho,他向我指出了 right solution

Javascript:

function onDataBound() {
var grid = $("#GridID").data("kendoGrid"); //Set GridID
var gridData = grid.dataSource.view();
for (var i = 0; i < gridData.length; i++) {
var gridItem = gridData[i];
if (!gridItem.CanBeDeleted) { //Condition
grid.table.find("tr[data-uid='" + gridItem.uid + "']").find(".k-grid-delete").hide(); //Remove button
}

//Second Iteration, if we have grouped columns
if (gridItem.items) {
for (var j = 0; j < gridItem.items.length; j++) {
var gridSubItem = gridItem.items[j];
if (!gridSubItem.CanBeDeleted) { //Condtion
grid.table.find("tr[data-uid='" + gridSubItem.uid + "']").find(".k-grid-delete").hide(); //Remove button
}
}
}
}
}

KendoGrid 助手:

.Events(e => e.DataBound("onDataBound"))

看看我的other answer以获得更好的解决方案。

关于c# - 通过 kendogrid 中的数据条件禁用命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36984369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com