如何通过给定的布尔值禁用行上的“删除”按钮?
给定此示例模型:
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以获得更好的解决方案。