jqGrid: using beforeSelectRow it disables my onCellSelect event

前端 未结 1 809
日久生厌
日久生厌 2020-12-06 23:21

I found a solution for my issue here: jqGrid multiselect - limit the selection of the row only using the checkbox

but that cancels out my onCellSelect event. In shor

相关标签:
1条回答
  • 2020-12-07 00:15

    You should understand that both beforeSelectRow and onCellSelect are processed inside of click event handler which are set on the grid body (see the part source code of jqGrid). Moreover the callback onCellSelect will be processed only if beforeSelectRow returns true so only if the row will be selected by the click (see the lines of code).

    What you can do as a workaround is just moving your current code of onCellSelect inside of beforeSelectRow:

    beforeSelectRow: function (rowid, e) {
        var $self = $(this),
            iCol = $.jgrid.getCellIndex($(e.target).closest("td")[0]),
            cm = $self.jqGrid("getGridParam", "colModel");
        if (cm[iCol].name === "cb") {
            return true;
        }
    
        if (iCol === 10) {
            OpenPopupWindow(rowid);
        }
    
        return false;
    }
    

    Just small common additional remarks. I would recommend you to change testing for column number to testing for the name of the column: cm[iCol].name === 'myColumnName' instead of iCol === 10. It will make the code more maintainable. Additionally I would recommend you to change the name of function OpenPopupWindow to openPopupWindow. The naming conversion of JavaScript require that one uses function with the first capital name only for constructors. If you choose the name of the function as OpenPopupWindow then you gives the tip to use it with new operator: var test = new OpenPopupWindow(rowid);. You see that even the color of OpenPopupWindow on stackoverflow is another as the color of $.jgrid.getCellIndex. Your current choice looks the same like the statement:

    var theVariableHoldOnlyIntegerValues = true; // assign boolean
    

    Renaming the function OpenPopupWindow to openPopupWindow bring the colors in order.

    0 讨论(0)
提交回复
热议问题