下面我有一个 kendoUI 网格,它从服务器获取数据。然后,用户可以编辑网格中的两列。我有一个单独的按钮,可以将数据发送回服务器,并且我不使用剑道网格的 UPDATE 传输来执行此操作。我遇到的问题是,如果我从网格中获取数据,它不会反射(reflect)用户输入。例如,要获取网格的基础数据,我执行以下操作:
products= $("#Grid").data("kendoGrid").dataSource.data()
但是当我迭代产品并检查 NewPrice 或 Comment 属性时,它始终为空白。以下是网格数据源的定义方式:
dataSource: {
transport: {
read: function (options) {
$.ajax({
url: "/Portal/API/GetProductPrices?id=" + pId,
dataType: "json",
success: function (data) {
localModel.userId = data.userId;
localModel.products = data.Products;
return options.success(model.products);
},
});
}
},
},
scrollable: false,
selectable: true,
schema: {
model: {
id: 'Id',
fields: {
Item: { type: 'string', editable: false },
Price: { type: 'number', editable: false },
NewPrice: { type: 'number', editable: true },
Comment: { type: 'string', editable: true, validation: { required: true } },
}
}
},
columns: [
{ field: "Price", title:"Price"},
{
field: "NewPrice", title: "<span class='editMode'>Proposed Value</span>", format: "{0:p}", attributes: { style: "text-align:center;" }, headerAttributes: { style: "text-align:center;" }, width: "50px",
template: "#=NewValueTemplate(data)#",
},
{ field: "Comment", title: "<span class='editMode viewWorkflowMode'>Notes</span>", width: "210px", template: "#=NotesTemplate(data)#" },
]
任何解决问题的建议将不胜感激
最佳答案
您尚未指定您正在使用的编辑类型。
您使用哪种类型:内联、批量或弹出?
只有这个是数据源吗?我没有看到更新功能。
我建议你看一下这三个演示。
Batch
Inline
Popup
最糟糕的是您没有指定editable属性的值。
默认情况下,它是 false,这意味着 kendoGrid 不可编辑,
即使您在模型字段上指定了 editable: true
。
Shortcut to "Editable" configuration
更新#2:
正如已经说过的here
If the data source is bound to a remote service (via the transport option) the data method will return the service response.
因此,当您在网格上使用 dataSource.data()
方法时,如果您没有正确更新数据源,您应该收到所有“旧”数据。 (我发现很奇怪,你在这些属性上得到空白值,可能是缓存问题)
正如我已经说过的,您的数据源不提供更新功能。
Here您是有关kendo dataSource中更新功能的配置的示例,其中包含对远程服务的请求。
建议您查看这两个示例:
示例 - 将更新指定为字符串 和 示例 - 将更新指定为函数
关于javascript - KendoUI - 使用底层模型从网格单元读取编辑的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29338867/