首页 > 解决方案 > How to conditionally set column to editable in kendo grid?

问题描述

Right now I am setting the entire grid to false for editing

(function(){
    let grid = $('#MyGrid').data('kendoGrid');
    grid.setOptions({
        editable: false
    });
})();

The problem I now have is that I need to be able to allow editing on two columns and am not sure how to do that?

So if my columns are Last, First, Age, Gender, I need to allow editing in Last and First while the rest are not allowed to edit.

EDIT

This is needed for when I set the grid as "read only", but some of the columns need to still be editable

标签: jquerykendo-uikendo-grid

解决方案


您可以通过数据源模型控制列的可编辑性:

将网格保留为可编辑,并根据需要关闭/打开可编辑字段。

示例(未经测试):

// make all fields uneditable (protected)
$.each(grid.dataSource.model.fields, function (name, options) {
  options.editable = false;
});

// unprotect the two fields in which changes will be allowed
grid.dataSource.model.fields["First"].editable = true;
grid.dataSource.model.fields["Last"].editable = true;

推荐阅读