lpfx
lpfx

Reputation: 1516

Grid cancel event not firing

I'm trying to use the cancel event in a grid, but the event is never fired.

Code:

$("#grid").kendoGrid({
        editable: true,
        toolbar: ["create", "save", "cancel"],
        dataSource: _dataSource,
        columns: [{
            title: "Description",
            field: "description"
        }, {
            title: "Active",
            field: "active"
        }],
        edit: function (e) {
            console.log("add row");
        },
        cancel: function (e) {
            console.log("cancel row");
        }
});

When I click on "Add new record", the console shows "add row", but when I click on "Cancel changes" nothing shows up in the console.

It is a pretty simple code and it is following the documentation, but am I missing something?

Version: Kendo UI v2016.1.112

Thanks!

Upvotes: 0

Views: 1538

Answers (1)

David Shorthose
David Shorthose

Reputation: 4497

The cancel event is fired only on the cancel button that is generated in the inline/pop up editing screen.

If you wish to intercept the toolbar version this demo should help:

http://dojo.telerik.com/omOhU

all I have done is attach the following event to the toolbar cancel button:

  $(".k-grid-cancel-changes").on('click', function(e){
          e.preventDefault(); 
          console.log("intercepted on cancel change event");

          return true;

        });

this will prevent the default click action first then does some action. In this case log to the console and then returns true to continue the action.

I have also added the edit command to show you that when clicking the cancel button when in edit mode the event is fired.

Hope this helps. Any issues give me a shout.

Upvotes: 1

Related Questions