This is a migrated thread and some comments may be shown as answers.

Handle Cancel click event for new record

3 Answers 283 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 17 Jul 2012, 08:23 PM

How would I implement the following (which is in an original MVC telerik grid onChange event handler) in a Kendo grid? Basically I need to capture the cancel click event and determine if it was from an add or an update.

$(e.form).find(".t-grid-cancel").click(function () {
 
    if (e.mode == "insert") {
        var urlPath = '@Url.Content( @"~\CatalogAdministration\RemoveBlankInventoryItem?inventoryItemId=")';
        urlPath += key;
 
        $.post(urlPath);
    }
 
});
 
$(e.form).find(".t-grid").data("tGrid").ajaxRequest({ inventoryItemId: key });

3 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 1
answered on 18 Jul 2012, 09:59 PM
This is what I think it should be, but it never fires. This is in the grid edit event.
$(e.form).find(".k-grid-cancel").click(function () {
 
    var insertMode = e.model.isNew();
 
    if (insertMode) {
    var urlPath = '@Url.Content( @"~\CatalogAdministration\RemoveBlankInventoryItem?inventoryItemId=")';
    urlPath += key;
 
    $.post(urlPath);
    }
 
});

What am I doing wrong?

Thanks!
0
Joe
Top achievements
Rank 1
answered on 19 Jul 2012, 01:39 PM
This was answered in another post so I will also post the answer here. The key was that "form" has been replaced with "container", so the first line should read:
$(e.container).find(".k-grid-cancel").click(function () {

This works great if the user actually clicks the cancel button but on the Telerik side it also would fire if the user cilcked the "X" button to close the popup window and this isn't occurring on the Kendo side. Is this a bug or is there another way to handle that event?

Thanks!



0
Joe
Top achievements
Rank 1
answered on 19 Jul 2012, 09:17 PM
To handle both the Cancel button click event and the user clicking the "X" to close the window you can use this:

$(e.container).find(".k-grid-cancel").add($(e.container).parent().find(".k-i-close")).click(function(e) {
  
       // event handler code
  
 });
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Joe
Top achievements
Rank 1
Share this question
or