How do you wire up a right-click event handler for an IgniteUI grid in an MVC app?
I need the jQuery event.clientX and clientY to open a context menu at the mouse cursor.
I also need the grid row id and right-clicked-cell.
Also: this right-click may occur over a row that is not selected. It may occur over any row, any cell, regardless of whether they are selected or not. I still need all the information above, even if there is no selection.
Hello Ray,
After investigating this further, I have determined that your requirement could be achieved by binding a method to the javascript contextmenu event.
Additionally, the right clicked cell could be accessed from the target of the event argument and the row id from the parent of the cell. This could be achieved as follows:
$("#gridProducts").contextmenu(function (evt) {
let cell = evt.target;
let rowID = evt.target.parentElement.attributes["data-id"].value;
let cellIndex = cell.cellIndex
let columnKey = $("#gridProducts").igGrid("option", "columns")[cellIndex].key;
});
Please test it on your side and let me know if you need any further information regarding this matter.
Regards, Monika Kirkova, Infragistics
The concept for Monika's answer is correct, so I give it the "Verified" answer. But a few things are incorrect.
This was correct. The rest of the code inside the function was slightly wrong, and did not work.
I ended up with something like this:
var ClickedCellHtmlElement = event.target;var ClickedRowHtmlElement = ClickedCellHtmlElement.parentElement.parentElement;var RowKey = $(ClickedRowHtmlElement).attr('data-id');var SomeSpecialValue = $('#mygrid').igGrid("getCellValue", RowKey, "somespecialcolumnkey");
The biggest issue was that the row was two parent elements up from the cell. Once you know that, you're good.