How do I know what was destroyed by the destroy command in the Kendo UI grid?

I am using the Kendo 2013.2.716 and JQuery 2.0.3 user interface and I place the grid on my page and my question is:

Does anyone know how to say what was destroyed by the destroy command from the grid?

For instance:

<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <link href="kendo.common.min.css" rel="stylesheet" /> <link href="kendo.default.min.css" rel="stylesheet" /> <script type="text/javascript" src="jquery-2.0.3.min.js"></script> <script type="text/javascript" src="kendo.all.min.js"></script> </head> <body> <div id="grid"></div> <script type="text/javascript"> $(document).ready(function() { var products = []; for(var i = 1; i <= 40; i++) { products.push({ ProductId: i, ProductName: "Product " + i }); } $("#grid").kendoGrid({ dataSource: { data: products, schema: { model: { id: "ProductId", fields: { ProductName: { type: "string" }, } } }, requestEnd: function (e) { if (e.type === "destroy") { alert("OK, so something got destroyed, but what??"); } } }, editable: "inline", columns: [ "ProductName", { command: "destroy", title: " ", width: "100px" } ] }); }); </script> </body> </html> 

I found the requestEnd in the documentation , but I'm completely confused to find out where the item will be destroyed. I just need the item id so that I can update other parts of my page accordingly.

I wonder if I need to grab it in advance somehow.

+4
source share
2 answers

Thanks to @Brett for specifying the destroy property on the transport. This code does the trick - letting me capture the destroyed (see Part of transport.destroy):

 <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <link href="kendo.common.min.css" rel="stylesheet" /> <link href="kendo.default.min.css" rel="stylesheet" /> <script type="text/javascript" src="jquery-2.0.3.min.js"></script> <script type="text/javascript" src="kendo.all.min.js"></script> </head> <body> <div id="grid"></div> <script type="text/javascript"> $(document).ready(function() { $("#grid").kendoGrid({ dataSource: { schema: { model: { id: "ProductId", fields: { ProductName: { type: "string" }, } } }, transport: { read: function (options) { var products = []; for(var i = 1; i <= 40; i++) { products.push({ ProductId: i, ProductName: "Product " + i }); } options.success(products); }, destroy: function (options) { var data = $("#grid") .data("kendoGrid").dataSource.data(); var products = []; for(var i = 0; i < data.length; i++) { if (data[i].ProductId !== options.data.ProductId) { products.push(data[i]) } } options.success(products); alert("Woo hoo - the product with the ID: " + options.data.ProductId + " was destroyed!"); } } }, editable: "inline", columns: [ "ProductName", { command: "destroy", title: " ", width: "100px" } ] }); }); </script> </body> </html> 
+1
source

You need to configure the transport object to your data source. Does your current configuration really break down? Of course, the element may disappear from your grid, but I wonder if it is still there in the data source. Perhaps this is what you intended.

http://docs.kendoui.com/api/framework/datasource#configuration-transport.destroy

If you're just looking for a way to get data that is being destroyed, connect to the parameterMap() function of the transport object. There you can manipulate the deleted object before the operation is completed.

http://docs.kendoui.com/api/framework/datasource#configuration-transport.parameterMap

+2
source

Source: https://habr.com/ru/post/1498363/


All Articles