[英]Kendo Grid: how to make datasource trigger update and create events
I am starting to look at how I would get my grid edits back to a service via the datasource. 我开始研究如何通过数据源将网格编辑返回到服务。
Following the documentation, I have set a local test data source as follows.. 根据文档,我将本地测试数据源设置如下。
function getDataSource() {
var gridData = [
{
col1: new CellData('1', 'data1-1'),
col2: new CellData('2', 'data1-2')
},
{
col1: new CellData('3', 'data2-1'),
col2: new CellData('4', 'data2-2')
},
];
var dataSrc = new kendo.data.DataSource({
batch: true,
transport: {
read: function (e) {
e.success(gridData);
},
update: function (e) {
// batch is enabled
var updateItems = e.data.models;
// This is not called
// on success
e.success();
},
create: function (e) {
e.success(e.data);
},
destroy: function (e) {
e.success();
}
}
});
return dataSrc;
}
I have a toolbar setup (with the "Save Changes"), and this is calling the SaveChanges configuration event, how ever, just cannot see what else I need to do to get the following to occur.. 我有一个工具栏设置(带有“保存更改”),并且这正在调用SaveChanges配置事件,但是,只是看不到我需要做些什么才能使以下事件发生。
I am having the same problem with the Add New record (though I can't get the grids "addRow" even to fire here) 我在“添加新记录”中遇到了同样的问题(尽管我无法在此处触发网格“ addRow”)
I have the running example here 我这里有运行示例
Any help would be great appreciated! 任何帮助将不胜感激!
You need to specify the DataSource schema for this to work: 您需要指定数据源架构才能使其工作:
var dataSrc = new kendo.data.DataSource({
batch: false, // true would mean transport functions get multipe models in e.data
transport: {
// ....
},
schema: {
data: function (response) {
return response;
},
model: {
id: "id",
fields: {
id: {
editable: false,
defaultValue: 0 // 0 == new / unsaved row
},
col1: {
editable: true,
// new items would have that using default add button
defaultValue: {
id: 0,
CategoryName: ""
},
fields: { id: { editable: true }, display: { editable: true }
},
col2: {
editable: true,
fields: { id: { editable: true }, display: { editable: true } }
}
}
}
}
});
Also note: 另请注意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.