Kendo ui 剑道用户界面调用自定义删除服务
如何调用自定义服务来删除Kendo UI网格中的行。此custon服务应具有可自定义的确认对话框选项。Kendo ui 剑道用户界面调用自定义删除服务,kendo-ui,kendo-grid,Kendo Ui,Kendo Grid,如何调用自定义服务来删除Kendo UI网格中的行。此custon服务应具有可自定义的确认对话框选项。 对此的任何想法都非常感谢您应该自定义kendo.data.DataSource的“destroy”属性,以指定URL并更新用于自定义确认的kendoGrid的“delete”命令代码 示例代码 $(document).ready(function () { var windowTemplate = kendo.template($("#windowTemplate").htm
对此的任何想法都非常感谢您应该自定义kendo.data.DataSource的“destroy”属性,以指定URL并更新用于自定义确认的kendoGrid的“delete”命令代码 示例代码
$(document).ready(function () {
var windowTemplate = kendo.template($("#windowTemplate").html());
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
var window = $("#window").kendoWindow({
title: "Are you sure you want to delete this record?",
visible: false, //the window will not appear before its .open method is called
width: "400px",
height: "200px",
}).data("kendoWindow");
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 430,
toolbar: ["create"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}"},
{ field: "UnitsInStock", title:"Units In Stock"},
{ field: "Discontinued"},
{ command: [
{name: "edit"},
{name: "Delete",
click: function(e){ //add a click event listener on the delete button
var tr = $(e.target).closest("tr"); //get the row for deletion
var data = this.dataItem(tr); //get the row data so it can be referred later
window.content(windowTemplate(data)); //send the row data object to the template and render it
window.open().center();
$("#yesButton").click(function(){
grid.dataSource.remove(data) //prepare a "destroy" request
grid.dataSource.sync() //actually send the request (might be ommited if the autoSync option is enabled in the dataSource)
window.close();
})
$("#noButton").click(function(){
window.close();
})
}
}
]}],
editable: {
mode: "inline"
}
}).data("kendoGrid");
});
摘自:
您可以将数据源中的“删除”选项设置为函数,并从该点开始执行任何操作。如果没有您的服务示例,我无法帮助您入门,但我可以将您链接到。但是如果我在单击“删除”按钮I时添加这样的内容,则会自动重定向到默认登录页。这在调试模式下不应发生。请查看传递到“删除”javaScript函数的事件参数(e)。你可能会发现它有一个Cancel属性,你可以设置它,或者你可以将它返回为false来阻止剑道代码继续。