Kendo 网格字段 editable:false 不适用于复杂模型
Kendo Grid field editable:false not working with complex model
我有一个网格,其中大多数单元格都绑定到第一级的模型成员。但是,我的模型还包含对象成员,并且我将一些列绑定到对象中的成员。我正在使用 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' }
]
如您所见,我正在将某些字段设置(并试图设置)为可编辑:false,这对 Id 字段以及我模型顶层的任何其他字段都适用,但它不适用于 Station.CallLetters 字段。 Station 列仍然是可编辑的。
其他一切正常。
我最初通过简单地创建一个包含相同数据项的列详细信息模板来解决这个问题:
var stationContent = kendo.template('${Station.CallLetters} ');
和
{ title: 'Station', template: stationContent, width: 80 },
但是,来自 Telerik:
这可以通过在单独的模型字段中指定可编辑选项来完成,该字段明确引用嵌套 属性。例如:
"Station.CallLetters": { editable: false },
这无疑是最受青睐的方法。奇怪,我至少没有尝试将密钥放在引号中。
我有一个网格,其中大多数单元格都绑定到第一级的模型成员。但是,我的模型还包含对象成员,并且我将一些列绑定到对象中的成员。我正在使用 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' }
]
如您所见,我正在将某些字段设置(并试图设置)为可编辑:false,这对 Id 字段以及我模型顶层的任何其他字段都适用,但它不适用于 Station.CallLetters 字段。 Station 列仍然是可编辑的。 其他一切正常。
我最初通过简单地创建一个包含相同数据项的列详细信息模板来解决这个问题:
var stationContent = kendo.template('${Station.CallLetters} ');
和
{ title: 'Station', template: stationContent, width: 80 },
但是,来自 Telerik:
这可以通过在单独的模型字段中指定可编辑选项来完成,该字段明确引用嵌套 属性。例如:
"Station.CallLetters": { editable: false },
这无疑是最受青睐的方法。奇怪,我至少没有尝试将密钥放在引号中。