簡體   English   中英

防止在kendo網格中編輯一行?

[英]Preventing editing a row in 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();
            }
        }
    }
});

但是當我使用它時,我在控制台中收到以下錯誤。

Uncaught TypeError: Cannot call method 'delegate' of null 

有人可以提出解決問題的方法。謝謝。

在目前的情況下,我建議使用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();
        }
    }
}

同意,即使我通過Change事件實現了行禁用功能。 這是代碼:

 function onRowSelect(val) {
    var curCell = $("#abc").find(".k-state-selected");
    if (curCell[0].innerText.indexOf('ABCD')>-1) {
        curCell[0].disabled = true;
    }

...


@(Html.Kendo().Grid<xyz>()
.Name("abc")  
.Selectable()   
.Events(e=>e.Change("onRowSelect"))
function onGridCellEdit(e) {

    this.closeCell();
}

在編輯行時將調用此函數,一旦此函數被命中,這將不允許更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM