防止在kendo网格中编辑一行?

Dee*_*epu 3 html javascript jquery kendo-ui kendo-grid

我正在使用kendo网格,在编辑行时,我正在检查该行是否可编辑.如果不可编辑,如何使所选行不可编辑.我正在检查edit网格功能.

$("#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();
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

但是当我使用它时,我在控制台中收到以下错误.

Uncaught TypeError: Cannot call method 'delegate' of null 
Run Code Online (Sandbox Code Playgroud)

有人可以提出解决问题的方法.谢谢.

Vla*_*iev 6

在目前的情况下,我建议使用dataBound事件迭代dataSource 视图数据并检查当前记录是否满足给定条件以禁用它的编辑按钮:

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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)