how to select row on right click?
how to select row on right click?
johnny83
Posts: 3Questions: 2Answers: 0
Hello! The select plugin is great. when I use select: true
it selects the row when click on it. I need same action on right click. Also need to get the row id on right/left click? Could you please help me to do this?
This discussion has been closed.
Replies
you can do with the mousedown event
Table = $("#exampletable ").DataTable({});
$('#exampletable tbody').on('mousedown', 'tr', function () {
exampletable .$('tr.selected').removeClass('selected');
$(this).addClass('selected');
});
But this does not work well in conjunction with multiselect and SHIFT selections.
For example, if you select one row with right-cllick (manually by setting the selected attribute), the next LMB-SHIFT will be taking the last left-clicked row and not the last right clicked as one would expect.
side note: RMB and SHIFT/CTRL does not work either.
live.datatables.net/toqugago/3/
I do not need RMB + CTRL/SHIFT, but it would be nice if it were possible to set the selected attribute **and ** the basis for the next LML+SHIFT. Is that possible?
This thread here might help, it discusses some right-click behaviour.
Colin
I know this thread, but I do not think it answers the problem. My comment is not addressing the interception of the right-click. This works fine as shown in the live example. My point is that the setting of the select property when intercepting the right-click does confuse the next left-click+SHIFT selection.
Or am I missing something there?
Coincidentally, I'm using the same contextmenu plugin as the other case opener, so maybe I'm overlooking something.
I suspect that's beyond the scope of this forum, it's likely to be a question better asked on StackOverflow. If you have a working demo of that, and can give steps on how to reproduce, we're happy to take a look,
Colin
Since the SHIFT/CTRL-Select is a DataTables feature i thought this is the correct place to ask. From my perspective, the last selected (selection by capturing RMB and setting the select attribute in the event handler) needs to be stored for the next SHIFT+mouse event.
User experience with the live example I provided at live.datatables.net/toqugago/3/ and LMB (as expected):
1. LMB on row 2 (row 2 is selected)
2. LMB on row 3 (row 3 is selected)
3. LMB + SHIFT on row 8 (rows 3..8 are selected)
Now when we add the right click as the selection (as is done in the example):
1. RMB on row 2 (row 2 is selected by the event handler)
2. RMB on row 3 (row 3 is selected by the event handler)
3. LMB + SHIFT on row 8 (rows 2..8 are selected) - expected behavior would be rows 3..8.
If there was a way to mark row 3 with the second step as the reference for step 3 (as it is done apparently with the first LMB-steps) it could be solved.
That is routine keyboard processing, not exclusive to DataTables.
@MarianL - You've got this code in your example:
That
mousedown
will trigger on left and mouse click. You could use:That's nothing to do with DataTables or Select though. See the MDN docs if you want to learn move about that.
Allan
Ok, thanks for your comments.