Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Preventing editing a row in kendo grid?

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.


    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;

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.

like image 673
Deepu Avatar asked Mar 25 '23 09:03


1 Answers

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");
            //grid.tbody.find("tr[data-uid='" + data[i].uid + "'] .k-grid-edit").remove();
like image 127
Vladimir Iliev Avatar answered Mar 29 '23 14:03

Vladimir Iliev