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,
This is an initial update to let you know that we have received your support request and I am currently looking into this matter for you. I will keep you posted on my progress and I will get back to you soon with more information or questions for you.
Please feel free to continue sending updates to this case at any time.
Regards, Monika Kirkova, Infragistics
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.
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.
On my side the row was the direct parent element of the clicked cell, however, I am glad that you were able to achieve your requirement.
Thank you for using Infragistics components.