Kendo UI 网格中的更新函数(与 AngularJs 一起使用)从不触发,与本地数据一起使用
Update function in Kendo UI Grid (using with AngularJs) never fires, using with Local Data
我有一个 Kendo UI 网格,它绑定到一个 KendoObservableArray。我正在使用内联编辑模式。我的选项声明如下:
valueMapCtrl.lookupMappingDetails = new kendo.data.ObservableArray([]);
valueMapCtrl.gridOptions = {
dataSource: new kendo.data.DataSource({
type: "json",
transport: {
read: function (options) {
options.success(valueMapCtrl.lookupMappingDetails);
},
update: function (options) {
console.log("Update", options);
options.success(options.data);
},
create: function (options) {
console.log("Create", options);
options.data.mappingId = mappingId;
mappingId = mappingId + 1;
options.success(options.data);
},
destroy: function (options) {
console.log("Delete", options);
options.success(options.data);
},
parameterMap: function (options, type) {
// this is optional - if we need to remove any parameters (due to partial OData support in WebAPI
console.log(options, type);
if (operation !== "read" && options.models) {
return JSON.stringify({models: options});
}
},
},
change: function (e) {
console.log("change: " + e.action);
// do something with e
},
error: function (e) {
// handle error
alert("Status: " + e.status + "; Error message: " + e.errorThrown);
},
//data: valueMapCtrl.dynamicData,
schema: {
model: {
id: "mappingId",
fields: {
mappingId: {editable: false, nullable: false, defaultValue: 0},
Col1: {
type: "string",
validation: {
required: true
}
},
Col2: {
type: "string",
validation: {
required: true
}
}
}
}
},
pageSize: 10,
batch: false
}),
columns: [{
field: "col1",
title: "Column 1"
}, {
field: "col2",
title: "Column 2"
}, {
command: /*"destroy"*/ ["edit", "destroy"],
title: " ",
width: "200px"
}],
selectable: "multiple cell",
allowCopy: "true",
//save: function (e) {
// console.log("Save", e);
//},
toolbar: ["create"],
height: 300,
navigatable: true,
filterable: true,
sortable: true,
pageable: true,
editable: "inline"
};
- 添加记录:正确创建火灾
- 删除记录:正确灭火
- 更新记录:没有任何反应,没有错误,我在更改事件 sync() 操作中看到的所有内容。
但是,如果我在我的选项中也声明保存,则会正确触发。
save: function (e) {
console.log("Save", e); //This fires on each update
},
我不确定上面的声明有什么问题;浏览了很多 forums/questions 以解决类似问题,但无法使其正常工作。有帮助吗?
我能够让它正常工作,在这里发帖以防有人遇到同样的问题。
valueMapCtrl.lookupMappingDetails = new kendo.data.ObservableArray([]);
我将这个可观察数组更改为普通数组,之后一切正常:
valueMapCtrl.lookupMappingDetails =[];// new kendo.data.ObservableArray([]);
此外,对于可观察数组,我还面临另一个问题;取消编辑是从网格中删除所有行。在此更改后,这也可以正常工作。虽然不确定原因并且无法在 telerik 文档中找到任何解释(无论我可以搜索什么)。
我有一个 Kendo UI 网格,它绑定到一个 KendoObservableArray。我正在使用内联编辑模式。我的选项声明如下:
valueMapCtrl.lookupMappingDetails = new kendo.data.ObservableArray([]);
valueMapCtrl.gridOptions = {
dataSource: new kendo.data.DataSource({
type: "json",
transport: {
read: function (options) {
options.success(valueMapCtrl.lookupMappingDetails);
},
update: function (options) {
console.log("Update", options);
options.success(options.data);
},
create: function (options) {
console.log("Create", options);
options.data.mappingId = mappingId;
mappingId = mappingId + 1;
options.success(options.data);
},
destroy: function (options) {
console.log("Delete", options);
options.success(options.data);
},
parameterMap: function (options, type) {
// this is optional - if we need to remove any parameters (due to partial OData support in WebAPI
console.log(options, type);
if (operation !== "read" && options.models) {
return JSON.stringify({models: options});
}
},
},
change: function (e) {
console.log("change: " + e.action);
// do something with e
},
error: function (e) {
// handle error
alert("Status: " + e.status + "; Error message: " + e.errorThrown);
},
//data: valueMapCtrl.dynamicData,
schema: {
model: {
id: "mappingId",
fields: {
mappingId: {editable: false, nullable: false, defaultValue: 0},
Col1: {
type: "string",
validation: {
required: true
}
},
Col2: {
type: "string",
validation: {
required: true
}
}
}
}
},
pageSize: 10,
batch: false
}),
columns: [{
field: "col1",
title: "Column 1"
}, {
field: "col2",
title: "Column 2"
}, {
command: /*"destroy"*/ ["edit", "destroy"],
title: " ",
width: "200px"
}],
selectable: "multiple cell",
allowCopy: "true",
//save: function (e) {
// console.log("Save", e);
//},
toolbar: ["create"],
height: 300,
navigatable: true,
filterable: true,
sortable: true,
pageable: true,
editable: "inline"
};
- 添加记录:正确创建火灾
- 删除记录:正确灭火
- 更新记录:没有任何反应,没有错误,我在更改事件 sync() 操作中看到的所有内容。
但是,如果我在我的选项中也声明保存,则会正确触发。
save: function (e) {
console.log("Save", e); //This fires on each update
},
我不确定上面的声明有什么问题;浏览了很多 forums/questions 以解决类似问题,但无法使其正常工作。有帮助吗?
我能够让它正常工作,在这里发帖以防有人遇到同样的问题。
valueMapCtrl.lookupMappingDetails = new kendo.data.ObservableArray([]);
我将这个可观察数组更改为普通数组,之后一切正常:
valueMapCtrl.lookupMappingDetails =[];// new kendo.data.ObservableArray([]);
此外,对于可观察数组,我还面临另一个问题;取消编辑是从网格中删除所有行。在此更改后,这也可以正常工作。虽然不确定原因并且无法在 telerik 文档中找到任何解释(无论我可以搜索什么)。