可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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"); }, ... });