我也遇到了同样的问题,但是在做了 2-3 天的 RnD 之后,得到了解决方案,我通过 dataSource API 和自定义工具栏命令实现了它。
toolbar: [{ text:"Add new record", className: "grid-add-new-record" }], // specify a custom toolbar button
$("#grid .grid-add-new-record").on("click", function(e) {
var dataSource = $("#grid").data("kendoGrid").dataSource;
var window = $("<div id='popupEditor'>")
.appendTo($("body"))
.kendoWindow({
title: "Add new record",
modal: true,
content: {
//sets window template
template: kendo.template($("#createTemplate").html())
}
})
.data("kendoWindow")
.center();
//determines at what position to insert the record (needed for pageable grids)
var index = dataSource.indexOf((dataSource.view() || [])[0]);
if (index < 0) {
index = 0;
}
//insets a new model in the dataSource
var model = dataSource.insert(index, {});
//binds the editing window to the form
kendo.bind(window.element, model);
//initialize the validator
var validator = $(window.element).kendoValidator().data("kendoValidator")
$("#btnUpdate").on("click", function(e) {
if (validator.validate()) {
dataSource.sync(); //sync changes
window.close();
window.element.remove();
}
});
$("#btnCancel").on("click", function(e) {
dataSource.cancelChanges(model); //cancel changes
window.close();
window.element.remove();
});
});
希望这会帮助你。
参考:Telerik 论坛
快乐编码!!