Kendo Grid cancel edit event

2019-03-24 08:44发布

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?

4条回答
你好瞎i
2楼-- · 2019-03-24 09:30

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");
    },
    ...
});
查看更多
手持菜刀,她持情操
3楼-- · 2019-03-24 09:36

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.

查看更多
Animai°情兽
4楼-- · 2019-03-24 09:43

Try this,

$("#grid").kendoGrid({
 columns: [
  { field: "name" },
  { field: "age" }
 ],
 dataSource: [
  { name: "Jane Doe", age: 30 },
  { name: "John Doe", age: 33 }
 ],
 dataBound: function(e) {
  $("#grid").on("mousedown", ".k-grid-cancel-changes", function (e) {
    //custom logic
  });
 }
});

In dataBound, wire click event for the kendo grid Toolbar cancel button. It will work.

查看更多
Animai°情兽
5楼-- · 2019-03-24 09:44

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:

查看更多
登录 后发表回答