jqGrid中onCellSelect函数的完全相反是什么?

What is the exact reverse of onCellSelect function in jqGrid?(jqGrid中onCellSelect函数的完全相反是什么?)

本文介绍了jqGrid中onCellSelect函数的完全相反是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码 -

 onCellSelect: function(rowid,iRow,iCol,e)
  {
        jQuery("#createrule").click(function(){
        hidePopup();
        showPopUp6();
      });     
   onCellSelect:

},

jqGrid中onCellSelect函数的正反面是什么?

What is the exact reverse of onCellSelect function in jqGrid?

推荐答案

如果用户在网格中单击,您不应该每次都注册新的 click 事件处理程序.

You should don't register new click event handler every time if the user click in the grid.

jqGrid 在创建网格期间注册 click 事件处理程序之一.因此,如果用户单击网格的某个单元格,您可以执行一些操作.rowidiCol 参数帮助您识别单击了哪个单元格和 e 参数(click 的 Event 对象event) 可以在需要时为您提供更多信息.jqGrid 是开源项目.因此,您可以随时检查源代码以更好地了解 onCellSelect 的作用以及将在哪个上下文中调用它.查看 行代码.

jqGrid register click event handler one during creating the grid. So you can do some actions in case of user click on some cell of the grid. Parameters rowid and iCol helps you to identify which cell was clicked and the e parameter (the Event object of click event) could gives you even more information if required. jqGrid is Open Source project. So you can any time examine the source code to understand better what onCellSelect do and in which context it will be called. Look at the lines of code.

只是一个例子你可以定义以下格式化程序

Just an example You can define the following formatter

formatter: function (cellValue, options, rowObject) {
    return "<span class='myLink'>" + cellValue + "</span>";
}

在名为myColumn"的列中并定义以下使用 myLink 类的 CSS 规则

in the column with the name "myColumn" and define the following CSS rule which uses myLink class

.myLink { text-decoration: underline; cursor: pointer; }

列中会有链接".

要检测用户点击了此类伪链接,您可以使用以下 onCellSelect 回调

To detect that the user clicks on such pseudo-link you can use the following onCellSelect callback

onCellSelect: function (rowid, iRow, iCol, e) {
    var $self = $(this), colModel = $self.jqGrid("getGridParam", "colModel");
    if (colModel[iCol].name === "myColumn") { // test for the click in myColumn column
        alert("OK here we can do something");
    }
}

警报将在点击列中的所有位置时显示,而不仅仅是在链接上.如果您只想检测链接上的点击,那么我们应该测试 e.tagret 这是用户点击的元素:

The alert will be displayed on click everywhere in the column, not only on the link. If you want to detect clicking only on the link then we should test e.tagret which is the element which was clicked by the user:

onCellSelect: function (rowid, iRow, iCol, e) {
    var $self = $(this), colModel = $self.jqGrid("getGridParam", "colModel");
    if (colModel[iCol].name === "myColumn" && $(e.tagret).hasClass("myLink")) {
        alert("OK, link is clicked and here we can do something");
    }
}

所以 onCellSelect 可用于处理网格每个单元格上的 click 事件.如果您需要另外禁止选择网格,则应使用 beforeSelectRow 而不是 onCellSelect.例如,请参阅答案.

So onCellSelect can be used to handle click event on every cell of the grid. If you need to suppress selection of the grid additionally then you should use beforeSelectRow instead of onCellSelect. See the answer for example.

这篇关于jqGrid中onCellSelect函数的完全相反是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:jqGrid中onCellSelect函数的完全相反是什么?

基础教程推荐