admin管理员组

文章数量:1293032

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.

Code

$("#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: "plete_date", width: "100px", title:"Completed"},
                { field: "serial_no", width: "100px", title: "Serial #"},
                { mand: ["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.

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.

Code

$("#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: "plete_date", width: "100px", title:"Completed"},
                { field: "serial_no", width: "100px", title: "Serial #"},
                { mand: ["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.

Share Improve this question edited Sep 17, 2014 at 4:41 웃웃웃웃웃 asked Apr 9, 2013 at 4:15 웃웃웃웃웃웃웃웃웃웃 12k15 gold badges62 silver badges94 bronze badges 3
  • Basically I would suggest to prevent the editing using dataBound event, however it depends on the current Grid configuration - could you please share the grid code? – Vladimir Iliev Commented Apr 9, 2013 at 5:51
  • I have edited the code.Can you look it – 웃웃웃웃웃 Commented Apr 9, 2013 at 6:08
  • Try googling for KendoUI readonly rows – OnaBai Commented Apr 9, 2013 at 7:16
Add a ment  | 

3 Answers 3

Reset to default 7

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();
        }
    }
}

Agree, even I achieved the row disability function via Change event. Here is the code:

 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();
}

this function will be called on edit of the row and once this function get hit, this won't allow to change.

本文标签: javascriptPreventing editing a row in kendo gridStack Overflow