I want the name of the column on right click of a column header in jqGrid. Any code would be appreciated.
You can bind The corresponding code could be about the following: The demo uses the code. Just use the right mouse click on the column header and you will see the results:contextmenu
event to all column headers. Every header is element and so its DOM support cellIndex property. The cellIndex property gives you the index of column header. If you would use the same index in colModel
you will get the definition of the column. The name
property gives you the column name.
var cm = $grid.jqGrid("getGridParam", "colModel");
$("th.ui-th-column", $grid[0].grid.hDiv).bind('contextmenu', function(e) {
var $th = $(e.currentTarget).closest("th");
if ($th.length > 0) {
alert("the header of the column '" + cm[$th[0].cellIndex].name +
"' was clicked");
e.preventDefault(); // don't display standard context menu
}
});