3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mayank
  • 1,351
  • 5
  • 23
  • 42
  • Which version of jqGrid you use? Which fork of jqGrid you use ([free jqGrid](https://github.com/free-jqgrid/jqGrid), [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or some old jqGrid in version <=4.7)? Do you use additional **editing** in the grid and want allow the rows with `Status` === `-1` be editable? – Oleg Nov 10 '15 at 11:16
  • I am using **jqGrid 4.5.2** free jqGrid,. There is no additional editing just using with param `multiselect : true`. – Mayank Nov 10 '15 at 11:23

1 Answers1

3

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for your valuable inputs. But the problem after applying the class `ui-state-disabled` the row gets disabled ( disabled row can alos have checked / unchecked values) and the checked status was not visible to the client. There are hyperlinks on some column of grid after applying the above class the hyperlink functionality was not working. Thanks – Mayank Nov 13 '15 at 07:29