jQuery UI Widgets › Forums › Grid › Cancel Event Rowselect or Rowclick
Tagged: event cancel, row cancel selection
This topic contains 5 replies, has 3 voices, and was last updated by SoftwareIsHappiness 8 years, 1 month ago.
-
Author
-
Hi everyone
We try to cancel the event rowselect or the rowclicked event to prevent that the user may accidently discard changed data. When he trys to change the row, we ask him a question if he wants to change the row and discard the data or just stay where he is. When clicks no we want to cancel/consume the click event.
We tryed it like in the tab event ‘selecting’ with ‘event.cancel = true’ but this doesnt work. Is it possible to prevent the user from selecting other rows?Greetings Mario
Hi Mario,
You can’t cancel events. If you have subscribed to an event, it will occur and your event handler will be called when the event is raised. In the event handlers, you should choose whether to execute your code or not depending on your logic.
Best regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks for your response.
I have the possibility to cancel the selection of tabs by setting the ‘selecting’ event to ‘event.cancel = true’.
$(‘#jqxTabs’).on(‘selecting’, function (event) { event.cancel = true; });
So it is possible to cancel this event to prevent other actions that occour after the event. The selection of a new tab in this case. My hope was that something like this exists for grids and rowselection too.
Greetings Mario
Hi Mario,
You should create an event handler and check to see if the columns to be re-ordered are allowed and if not then use
event.cancel = true
to prevent the re-order. For example:$('#jqxgrid').on('columnreordered', function (event) { var allowed = true; /* Write you condition to set variable allowed to false if columns should not be re-ordered */ // event arguments. var args = event.args; // column text. var columnText = args.columntext; // column data field. var dataField = args.datafield; // old column index. var oldIndex = args.oldindex; // new column index. var newIndex = args.newindex; if (allowed == false) event.cancel = true; });
NOTE: You are bind to the “columnreordered” of the jqxgrid component.
Hope this helps! 🙂
MichaelHi Mario,
I accidentally posted the above reply to your post. However, I thought I would attempt to “unselect” rows from within the grid rowclick however the only way I could accomplish this is to trigger an event from outside of the grid. I am not familiar enough with jQWidgets. However what you are trying to accomplish may be restricted to the widgets scope. I’m sure you could create a workaround if the scope prevents what you are seeking but if you are presenting the user with a dialog box “asking a question” then this is what you will be doing anyways.
$('#jqxgrid').on('rowclick', function (event) { $("#button").trigger('click'); }); $("#button").on('click', function () { $('#jqxgrid').jqxGrid('clearselection'); });
Hope this helps!
Michael 🙂You might consider this post… http://www.jqwidgets.com/community/topic/disable-specific-rows-selecction/
-
AuthorPosts
You must be logged in to reply to this topic.