Kendo Grid-动态更改每行的单元格可编辑/不可编辑 [英] Kendo Grid - Make a cell editable/uneditable for each row dynamically

查看:974
本文介绍了Kendo Grid-动态更改每行的单元格可编辑/不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Kendo网格,根据第一列中的值,COR ABA号可能是可编辑的,也可能是不可编辑的.因此,如果NOC Code =='C01',则COR ABA号是可编辑的,否则不是可编辑的.

I have a Kendo Grid where the COR ABA No. may or may not be editable, depending on a value in the first column. So, if NOC Code=='C01', then COR ABA No. is editable, otherwise it is not.

我通过在列上添加Edit事件并在不允许编辑的情况下禁用Kendo创建的HTML输入的编辑处理程序来实现此目的. (在网格定义中,我要启动Editable(true)).我想通过在网格的DataBound事件中进行逻辑检查来做到这一点.也就是说,在绑定所有数据之后,请对数据进行迭代,确定何时该列不应该是可编辑的,并以某种方式防止这种情况.我的想法是,如上所述,当使用Editable(true)时,仅删除I ASSUME Kendo为单元格添加的单击处理程序.是这样吗?或如何?谢谢!

I have achieved this by adding the Edit event on the columns and in that edit handler disabling the HTML input Kendo creates, when no editing is allowed. (In the grid definition, I have Editable(true) to start). I want instead to do this by doing the logic check in the DataBound event for the grid. That is, after all data is bound, iterate over the data, determine when the column should NOT be editable, and prevent this somehow. My idea is to simply remove the click handler that I ASSUME Kendo adds for a cell when using Editable(true) as stated above. Is this the way? Or how? Thanks!

推荐答案

如果您不想允许用户编辑单元格,建议使用另一种方法,而不是在edit事件上调用closeCell().这样,当用户单击该单元格进行编辑时,该单元格将不会显示输入.

I suggest another way, instead call closeCell() on edit event, if you do not want to allow the user to edit the cell. In doing so, the cell will not display an input when the user clicks it to edit it.

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  columns: [
    { field: "id" },
    { field: "name" },
    { field: "age" }
  ],
  dataSource: {
    data: [
      { id: 1, name: "Jane Doe", age: 30 },
      { id: 2, name: "John Doe", age: 33 }
    ],
    schema: {
      model: {
        id: "id",
        fields: {
          "id": { type: "number" }
        }
      }
    }
  },
  editable: "incell",
  toolbar:["create"],
  edit: function(e) {
    if (!e.model.isNew() && e.container.index() == 0) {
      var grid = $("#grid").data("kendoGrid");
      grid.closeCell();
    }
  }
});
</script>

这篇关于Kendo Grid-动态更改每行的单元格可编辑/不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆