打开 Kendo 网格批量编辑后,我知道您可以连接到创建、更新和销毁命令,当您单击保存更改"时,Kendo 将向服务器发送 3 个单独的命令.
With Kendo grid batch editing turned on, I know that you can hook into the create, update and destroy commands where Kendo will send 3 separate commands to the server when you click on Save Changes.
我想知道是否有任何方法可以像事务一样将所有三组更新作为对服务器的单个调用发送.或者甚至按照指定的顺序发送每个,在发送下一个之前检查是否成功.
I was wondering if there was any way to send all three sets of updates as a single call to the server -like a transaction. Or even send each in a specified order, with a check for success before sending the next .
我能想出的唯一方法是有一个自定义的保存更改实现,当调用时,它会查找网格数据源以找出所有已添加的行(isNew() 用于添加行)、删除(_destroyed对于已删除的行)、更新(对于更新的行是 isDirty),然后使用已识别的数据集使用 ajax 对服务器端点进行我自己的调用.
The only way I could come up with was to have a custom Save Changes implementation which ,when invoked, would lookup the grid datasource to find out all rows that have been added (isNew() for added rows), deleted (_destroyed for deleted rows), updated (isDirty for updated rows) and then craft my own call to a server endpoint using ajax using the identified datasets.
推荐答案Telerik 最近在他们的代码库中发布了一个解决方法:www.kendoui.com/code-library/mvc/grid/save-all-changes-with-one-request.aspx.不幸的是,解决方法相当简单.它提供了一个很好的示例,说明如何捕获损坏的、脏的和新的记录,但最后还是挥手处理响应中的任何错误并在成功时同步数据源.另请注意,在发出 ajax 请求之前,没有检查以确保有被破坏的、脏的或新的记录.
Telerik posted a work-around in their code library recently: www.kendoui/code-library/mvc/grid/save-all-changes-with-one-request.aspx. Unfortunately the work-around is rather bare-bones. It gives a good example of how to capture destroyed, dirty, and new records but finishes with some hand waving to handle any errors in the response and synchronizing the data source on success. Also note that there is no check to ensure there are destroyed, dirty, or new records before making the ajax request.
这是相关的代码.从上面的链接下载完整示例以查看网格是如何设置的并确保您拥有最新版本.
Here is the relevant code. Download the full example from the link above to see how the grid is setup and to ensure you have the latest version.
function sendData() { var grid = $("#Grid").data("kendoGrid"), parameterMap = grid.dataSource.transport.parameterMap; //get the new and the updated records var currentData = grid.dataSource.data(); var updatedRecords = []; var newRecords = []; for (var i = 0; i < currentData.length; i++) { if (currentData[i].isNew()) { //this record is new newRecords.push(currentData[i].toJSON()); } else if(currentData[i].dirty) { updatedRecords.push(currentData[i].toJSON()); } } //this records are deleted var deletedRecords = []; for (var i = 0; i < grid.dataSource._destroyed.length; i++) { deletedRecords.push(grid.dataSource._destroyed[i].toJSON()); } var data = {}; $.extend(data, parameterMap({ updated: updatedRecords }), parameterMap({ deleted: deletedRecords }), parameterMap({ new: newRecords })); $.ajax({ url: "/Home/UpdateCreateDelete", data: data, type: "POST", error: function () { //Handle the server errors using the approach from the previous example }, success: function () { alert("update on server is completed"); grid.dataSource._destroyed = []; //refresh the grid - optional grid.dataSource.read(); } }) }更多推荐
剑道网格批量编辑
发布评论