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

Cancel the change event

1 Answer 1410 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 2
Eric asked on 13 Sep 2012, 03:05 PM
How would one go about cancelling the change event?

I need to check a variable when the change event is fired and depending upon the variable value:
  1. prevent the change event from bubbling/cancel the event 
  2. maintain the selected state of any rows that were selected prior to the change event firing

Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 14 Sep 2012, 11:58 AM
Hi Eric,

 
Basically you can prevent events using the jQuery .preventDefault() method.

Also please note that preventing the change event wont prevent loosing the current selection, however this can be achieved by using function like the following:

function onChangeEvent() {
           if (lastSelection == null) {
               // Saves first selection
               lastSelection = $("#grid .k-state-selected");
           }
           else {
                
               if (selectionValidation()) {
                   // Saves last confirmed selection
                   lastSelection = $("#grid .k-state-selected");
                   return;
               }
               else {
                   // Clear current selection, and return to last saved selection
                   $(this.select()).removeClass("k-state-selected");
                   $(lastSelection).addClass("k-state-selected");
               }
           }
       }
 
       function selectionValidation() {
           // Place your validation logic here
           return confirm("Change selection");
       }
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Eric
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Share this question
or