Kendo Grid字段可编辑:false不使用复杂模型

时间:2015-03-14 02:56:14

标签: angularjs kendo-grid

我有一个网格,大多数单元格绑定到第一级的模型成员。但是,我的模型还包含对象成员,我将几列绑定到对象中的成员。我正在使用incell编辑,但我显然想限制某些字段的编辑。

以下是我的模型的一个小例子:

{
   Id: 123456,
   Name: 'some name',
   Cost: 34.56,
   Station: {
      CallLetters: 'WKGB',
      NetworkId: 123
   }
}

我能够使用以下内容绑定到网格而没有任何问题:

schema: {
   model: {
      fields: {
         Id: { type: "number", editable: false },
         Name: { type: "string" },
         Cost: { type: "number" },
         Station: { CallLetters: { type: "string", editable: false }, editable: false }
      }
   }
}

columns = [
   { title: 'Id', field: 'Id', hidden: true, menu: false },
   { title: 'Station', field: 'Station.CallLetters', width: 80 },
   { title: 'Name', field: 'Name', width: 120 },
   { title: 'Cost', field: 'Cost', width: 95, format: '0:c2' }
]

正如您所看到的,我正在设置(并尝试设置)某些字段为editable:false,这适用于Id字段以及我模型顶层的任何其他字段,但它没有为Station.CallLetters字段工作。 “站”列仍可编辑。 其他一切都很好。

1 个答案:

答案 0 :(得分:2)

我最初只是通过创建一个包含相同数据项的列详细信息模板来解决这个问题:

var stationContent = kendo.template('${Station.CallLetters} ');

{ title: 'Station', template: stationContent, width: 80 },

然而,来自Telerik:

这可以通过在单独的模型字段中指定可编辑选项来完成,该字段显式引用嵌套属性。例如:

"Station.CallLetters": { editable: false },

这很容易成为最有利的方法。奇怪我至少没有试着把钥匙放在引号中。

相关问题