Kendo Grid cancel edit event

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

I'm using the edit event on a Kendo grid to show a couple of hidden columns. I'll then hide them again on the save event.

Problem I have is that there doesn't appear to be an event for cancelling edit mode, so the column get screwed up if the user clicks cancel.

Is there an undocumented event for cancel or do I need to find a workaround?

回答1:

Basically there is no such "Cancel" event, however you can attach click event on the "Cancel" button in the еdit event of the Grid. Please check the example below:

function onEdit(e) {    e.container.find(".k-grid-cancel").bind("click", function () {       //your code here    })  } 

EDIT: From some time the Grid have "cancel" event which can be used instead of the above solution:



回答2:

I've been looking for an answer to the same question but this didn't work for me. I had a scenario where new and edited records within my grid are validated within my controller and error messages are added to the ModelState's ModelError collection. I had hooked up the grid's datasource error event which then displayed the error message within an alert, and then added the following which reset the changes:

$('#MyGrid').data("kendoGrid").cancelChanges(); 

It was a neat solution for me because I am using paging and the current page the user is viewing is preserved.



回答3:

Contrary to what the accepted answer states there is in fact a cancel event just like the edit event.

$("#grid").kendoGrid({     ...     edit: function(e) {         alert("edit")     },     cancel: function(e) {         alert("cancel");     },     ... }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!