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
433 views
in Technique[技术] by (71.8m points)

javascript - How to restrict particular Row to be selected on Header Select All event in JQGRID

Using jqGrid I have disabled the row selection on checkbox column click by following event:

beforeSelectRow: function (rowid, e) {
    var $myGrid = $(this),
        i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
        cm = $myGrid.jqGrid('getGridParam', 'colModel');

    var rowData = $grid.getRowData(rowid);
    var $isSelectable = true;
    if (rowData != null) {
        if (rowData.Status == -1) // Row selection depends on 'Status' property row data ( -1 : not selectable else selectable)
            $isSelectable = false;
        }
        return $isSelectable;
    },

But When i tried to click on Header Checkbox it selects all the rows. I am trying to use event onSelectAll but it is getting called after the row selection process, and I am unable to find the appropriate event that call before the Row Selection change. Please suggest appropriate solution.

Edit :

The grid's Checkbox could have value (i.e. Checked / Unchecked) even if it is disabled.

The grid have hyperlinks that navigate to another page.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

The simplest way to implement your requirements is the usage of rowattr to disable the rows having Status equal to -1.

The demo uses the free jqGrid 4.10.0 and the results on selection of all rows looks like on the picture below:

enter image description here

It uses the following rowattr:

rowattr: function (rd) {
    if (rd.closed) {
        return {
            "class": $(this).jqGrid("getGuiStyles", "states.disabled")
        };
    }
}

The code use closed column instead of Status column and the input values of the demo are boolean instead of numeric or strings in your case. You can easy modify the above code to your purpose.

In case of using old jqGrid 4.5.2 you can modify the above code to

rowattr: function (rd) {
    if (rd.closed) {
        return {
            "class": "ui-state-disabled ui-jqgrid-disablePointerEvents"
        };
    }
}

and define CSS class ui-jqgrid-disablePointerEvents as the following:

.ui-jqgrid-disablePointerEvents {
    pointer-events: none;
}

The demo uses jqGrid 4.5.2 and it works too.


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

...