Switch off / on Kendo UI grid editable mode

倾然丶 夕夏残阳落幕 提交于 2019-12-23 03:16:10

问题


I am using a Kendo grid where grid's editable option needs to be switched on / off based some flag. Can somebody help that how can it be achieved.

     <button class="change-mode">Change Edit Mode</button>

     $('.change-mode').click(function(){
          //Swit ched on /off here  based on  some flag      
          //console.log($("#grid"));
         $("#grid").options.editable = false;    
     });

Here is the jsfiddle


回答1:


If you are using the latest release of KendoUI (2014 Q3) you cannot change options directly but you can use setOptions.

<button class="change-mode">Change Edit Mode</button>

$('.change-mode').click(function(){
    //Swit ched on /off here  based on  some flag 
    var grid = $("#grid").data("kendoGrid");
    var enabled = grid.options.editable !== false;
    grid.setOptions({editable: !enabled}); 
});

Your JSFiddle modified here: http://jsfiddle.net/OnaBai/mnmm1bqw/4/




回答2:


Use edit function and global variable to disable and enable edit mode

some thing like below

var globFlag=true;

$("#grid").kendoGrid({

  ...

  edit:  function(e) {
            if ( globFlag ) {
               this.closeCell();
            }
        }

  ...

});


$('.change-mode').click(function(){
          if(globFlag)
               globFlag=false;
          else
               globFlag=true;

 });


来源:https://stackoverflow.com/questions/27120287/switch-off-on-kendo-ui-grid-editable-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!