jqGrid-在jqGrid中的列的右键单击上确定列的名称 [英] jqGrid - determine name of column on right click of a column in jqGrid

查看:107
本文介绍了jqGrid-在jqGrid中的列的右键单击上确定列的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要右键单击jqGrid中的列标题的列名称.任何代码将不胜感激.

I want the name of the column on right click of a column header in jqGrid. Any code would be appreciated.

推荐答案

您可以将contextmenu事件绑定到所有列标题.每个标头都是<th>元素,因此其DOM支持 cellIndex 属性. cellIndex 属性为您提供列标题的索引.如果要在colModel中使用相同的索引,则将获得列的定义. name属性为您提供列名.

You can bind contextmenu event to all column headers. Every header is <th> 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.

相应的代码可能与以下内容有关:

The corresponding code could be about the following:

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
    }
});

演示使用该代码.只需使用鼠标右键单击列标题,您将看到结果:

The demo uses the code. Just use the right mouse click on the column header and you will see the results:

这篇关于jqGrid-在jqGrid中的列的右键单击上确定列的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆