Posted 29 April 2019, 9:48 pm EST
Hello!
The easiest way to do this is by adding a handler to the “contextmenu” event, which fires when the user right-clicks an item. For example:
https://jsfiddle.net/Wijmo5/4j1nvm9u/
The fiddle handles the “contextmenu” event with this code:
theGrid.hostElement.addEventListener('contextmenu', function(e) {
var ht = theGrid.hitTest(e);
if (ht.panel == theGrid.cells) {
var item = theGrid.rows[ht.row].dataItem;
alert('you right-clicked ' + item.name);
theGrid.select(ht.row, 0);
e.preventDefault();
}
})
This shows how to handle click events (mouse down, then up on the same element).
If you want to perform an action on the mousedown event (before the user releases the button), the code is almost the same:
https://jsfiddle.net/Wijmo5/1ach9x0L/
theGrid.hostElement.addEventListener('mousedown', function(e) {
if (e.button == 2) { // right button
var ht = theGrid.hitTest(e);
if (ht.panel == theGrid.cells) {
var item = theGrid.rows[ht.row].dataItem;
alert('you right-clicked ' + item.name);
theGrid.select(ht.row, 0);
e.preventDefault();
}
}
})
I hope this helps.