jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Cancel row selection
This topic contains 4 replies, has 2 voices, and was last updated by manolito 4 years, 7 months ago.
-
AuthorCancel row selection Posts
-
Hi,
I am trying to cancel the selection change of a row when the user changes the current row selection (through mouse or keyboard).
I know there is an event “rowselect”, but it is not working for what we need:
this.handleGridRowSelectEvent = function (rowindex) { if (revertingGridRowSelection) return; // To avoid infinite event loop revertingGridRowSelection = true; self.$gridPatternGroups.jqxGrid("selectrow", currentrowindex); revertingGridRowSelection = false; };
What happens is that the “rowindex” is selected in the end, instead of “currentrowindex”. It seems the “rowselect” event is working as a “beforerowselect”? And in that case, if I try to override the selection, the event finishes and the grid itself overrides my decision.
Is there any way to cancel this event? If we do this, then it works (i.e: it cancels the selection change and keeps the current):
this.handleGridRowSelectEvent = function (rowindex) { throw "Forcing an exception."; };
But obviously that solution is kind of ugly. And you never know if any side effect may be occurring.
Does it seem we are missing an “afterrowselect” event here? Or is there any proper way to achieve what we want?
Thanks in advance.
Edited:
Other thing. I know we can disable row selection. But that is not what we want here. The idea is to ignore the user selection when a condition happens. I have omitted that condition in my code above.
Hello manolito,
You could unselect the other row and select the desired one.
Please, take a look at this example.Best Regards,
Hristo HristovjQWidgets team
https://www.jqwidgets.comI see, so the key here is the setTimeout() function to get the new “rowselect” event out of the current event chaining. In effect, you can see a kind of glitch because the initial selection is actually happening, just before the setTimeout() triggers and gets back to the previous selection.
I understand there is no other way due to the current jqxGrid design. In fact, in your example there is no need to use “unselectrow”, since it has no effect at all: once the “rowselect” event ends, some other thing happens within the jqxGrid control, overriding whatever you decided during the event handler.
It is the same effect I described in my post: in matter of selection, you cannot do anything during the event handler, because jqxGrid will override it. An “afterselectrow” event type might be missing to take into account this use case properly.
I will test your approach in my real case to see if that glitch can be tolerable.
Thanks for your help.
Hello manolito,
Unfortunately, this is what I could suggest to you with the current API.
Another option that I could suggest to you is the jqxDataTable with theselectionMode: "custom"
option.
Also, you could use our Smart.Grid which provides such behavior, too.
You could use it in that way:
grid.selection.action = "none";
This is part of our library and if you have a license it is valid for both.Best Regards,
Hristo HristovjQWidgets team
https://www.jqwidgets.comI will check that out.
Thanks!
-
AuthorPosts
You must be logged in to reply to this topic.