Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

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

My code -

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

},

What is the exact reverse of onCellSelect function in jqGrid?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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

You will have "links" in the column.

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...