阻止 Kendo 网格自动保存
Prevent Kendo Grid from auto saving
如何阻止 kendo grid/datasource 自动将更改发布到服务器?
我试过拦截 Grid 的 saveChanges 但它不是由 Updated 命令触发的。根据 docs,默认情况下 DataSource 的自动同步应该是 false,但我继续设置它但没有效果。
$("#items-grid").kendoGrid({
dataSource: {
autoSync: false,
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("
ItemList ", "
PurchaseRequisition ", new {prId = @Model.Id }))",
type: "POST",
dataType: "json",
},
update: {
url: "@Html.Raw(Url.Action("
ItemEdit ", "
PurchaseRequisition "))",
type: "POST",
dataType: "json",
}
},
sync: function(e) {
console.log("sync complete");
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
/...
}
}
},
},
saveChanges: function(e) {
// not fired from Update command
e.preventDefault();
},
columns: [{
// ...
}, {
command: [{
name: "edit",
text: {
edit: "Edit",
update: "Update",
cancel: "Cancel"
}
}],
width: 100
}]
});
});
您可以尝试将 dataSource
批处理设置为 true
。
var dataSource = new kendo.data.DataSource({
transport: {...},
batch: true
...}
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 550,
toolbar: ["create", "save", "cancel"],
columns: [...],
editable: true
});
注意:这是内联编辑。
你可以在官方页面上看到一个例子:Batch editing
如何阻止 kendo grid/datasource 自动将更改发布到服务器?
我试过拦截 Grid 的 saveChanges 但它不是由 Updated 命令触发的。根据 docs,默认情况下 DataSource 的自动同步应该是 false,但我继续设置它但没有效果。
$("#items-grid").kendoGrid({
dataSource: {
autoSync: false,
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("
ItemList ", "
PurchaseRequisition ", new {prId = @Model.Id }))",
type: "POST",
dataType: "json",
},
update: {
url: "@Html.Raw(Url.Action("
ItemEdit ", "
PurchaseRequisition "))",
type: "POST",
dataType: "json",
}
},
sync: function(e) {
console.log("sync complete");
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
/...
}
}
},
},
saveChanges: function(e) {
// not fired from Update command
e.preventDefault();
},
columns: [{
// ...
}, {
command: [{
name: "edit",
text: {
edit: "Edit",
update: "Update",
cancel: "Cancel"
}
}],
width: 100
}]
});
});
您可以尝试将 dataSource
批处理设置为 true
。
var dataSource = new kendo.data.DataSource({
transport: {...},
batch: true
...}
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 550,
toolbar: ["create", "save", "cancel"],
columns: [...],
editable: true
});
注意:这是内联编辑。
你可以在官方页面上看到一个例子:Batch editing