2013-04-09 65 views
3

我正在使用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 

有人可以提出一种方法来解决它。谢谢。

+0

基本上我会建议,以防止编辑使用dataBound事件,但它取决于当前的网格配置 - 请你分享网格代码? – 2013-04-09 05:51:07

+0

我编辑了代码。你可以看它 – 2013-04-09 06:08:43

+0

尝试谷歌搜索_KendoUI只读行_ – OnaBai 2013-04-09 07:16:42

回答

6

在目前的情况下,我会建议使用数据绑定事件在数据源迭代view数据,并检查当前记录遇见给定的条件来禁用它的编辑按钮:

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

应该作为答案作为! – billybob 2013-10-15 14:01:07

0

同意,甚至我实现了通过更改事件排行残疾功能。这里是代码:

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"))