Switch off / on Kendo UI grid editable mode

2019-06-02 09:49发布

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

2条回答
男人必须洒脱
2楼-- · 2019-06-02 09:55

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;

 });
查看更多
啃猪蹄的小仙女
3楼-- · 2019-06-02 10:09

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/

查看更多
登录 后发表回答