防止在剑道网格中编辑一行? [英] Preventing editing a row in kendo grid?
本文介绍了防止在剑道网格中编辑一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用剑道网格,在编辑一行时,我正在检查该行是否可编辑.因此,如果所选行不可编辑,如何使其不可编辑.我正在检查 edit代码>网格的功能.
I am using kendo grid and while editing a row i am checking whther that row is editable or not.So how to make the selected row non editable if its not editable.I am doing the checking in edit
function of grid.
代码
$("#grid").kendoGrid({
dataSource : ds,
selectable : "multiple",
sortable : true,
filterable : false,
reorderable: true,
scrollable : false,
toolbar : ["create"],
columns: [
{ field: "event", width: "120px", title: "Event Type"},
{ field: "event_id", width: "120px", title: "Event ID"},
{ field: "addr_no_or_type", width: "120px", title:"Address"},
{ field: "event_rate", width: "100px", title: "Rate"},
{ field: "sched_date", width: "100px", title: "Scheduled"},
{ field: "complete_date", width: "100px", title:"Completed"},
{ field: "serial_no", width: "100px", title: "Serial #"},
{ command: ["edit", "destroy"], title: "Options", width: "170px"}
],
editable: "inline",
edit : function(e){
selectedRowIndex = $("#grid").data("kendoGrid").select().index();
if (selectedRowIndex >= 0) {
var grid = $("#grid").data("kendoGrid");
var selectedItem = grid.dataItem(grid.select());
var slno = selectedItem.serial_no;
if(slno!=0){
grid.cancelRow();
}
}
}
});
但是当我使用它时,我在控制台中收到以下错误.
But when i use this i'm getting the following error in console.
Uncaught TypeError: Cannot call method 'delegate' of null
有人可以提出解决方法吗.谢谢.
Can somebody suggest a method to resolve it.Thank you.
推荐答案
在目前的情况下,我建议使用 dataBound 事件来迭代 dataSource 查看 数据并检查当前记录是否满足给定条件以禁用其编辑按钮:
In current case I would suggest to use the dataBound event to iterate over the dataSource view data and check if the current record met given condition to disable it's edit button:
function onDataBound(e) {
//this solution makes all rows editable / not editable initially
var grid = e.sender;
var data = grid.dataSource.view();
for (var i = 0; i < data.length; i++) {
//check your custom condition
if (data[i].OrderID % 2 == 0) {
var editButton = grid.tbody.find("tr[data-uid='" + data[i].uid + "'] .k-grid-edit");
editButton.addClass("k-state-disabled").removeClass("k-grid-edit");
//or
//grid.tbody.find("tr[data-uid='" + data[i].uid + "'] .k-grid-edit").remove();
}
}
}
这篇关于防止在剑道网格中编辑一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文