What is the exact reverse of the onCellSelect function in jqGrid?

My code is -

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

      

},

What is the exact reverse of the function onCellSelect

in jqGrid?

+3


source to share


1 answer


You don't have to register a new event handler click

every time the user clicks on the grid.

jqGrid register click

one event handler during grid creation. This way you can do some action if the user clicks on the grid cell. Parameters rowid

and iCol

help determine which cell was clicked, and the parameter e

(the Event object of the event click

) can provide you with even more information if needed. jqGrid is an open source project. Therefore, you can study the source code at any time to better understand what to do onCellSelect

and in what 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>";
}

      

in the column named "myColumn" and define the following CSS rule that uses the myLink

class

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

      



You will have "links" in the column.

To detect that the user clicks on such a 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");
    }
}

      

The warning will be displayed on click everywhere in the column, not just on the link. If you only want to detect a click on a link, we have to test e.tagret

which is the element that 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");
    }
}

      

So onCellSelect

can be used to handle the event click

in each cell of the grid. If you need to further disable mesh selection, you should use beforeSelectRow

instead onCellSelect

. See the answer for example.

+1


source







All Articles