如何限制在 JQGRID 中的 Header Select All 事件上选择特定行
使用 jqGrid,我通过以下事件禁用了复选框列上的行选择:
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);变量 $isSelectable = true;如果(行数据!= null){if (rowData.Status == -1)//行选择取决于 'Status' 属性行数据(-1:不可选,否则可选)$isSelectable = 假;}返回 $isSelectable;},
但是当我尝试单击标题复选框时,它会选择所有行.我正在尝试使用事件 onSelectAll
但它在行选择过程之后被调用,并且我无法在行选择更改之前找到调用的适当事件.请提出适当的解决方案.
即使被禁用,网格的复选框也可能具有值(即选中/未选中).
网格具有导航到另一个页面的超链接.
解决方案实现您的需求的最简单方法是使用 rowattr
来禁用具有 状态
等于-1.
它使用以下 rowattr
:
rowattr: 函数 (rd) {如果(rd.close){返回 {"类": $(this).jqGrid("getGuiStyles", "states.disabled")};}}
代码使用 closed
列而不是 Status
列,并且在您的情况下,演示的输入值是布尔值而不是数字或字符串.您可以根据自己的目的轻松修改上述代码.
如果使用旧的 jqGrid 4.5.2 可以将上面的代码修改为
rowattr: 函数 (rd) {如果(rd.close){返回 {类":ui-state-disabled ui-jqgrid-disablePointerEvents"};}}
并定义CSS类ui-jqgrid-disablePointerEvents
如下:
.ui-jqgrid-disablePointerEvents {指针事件:无;}
演示使用jqGrid 4.5.2和它也可以.
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.
解决方案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:
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.
相关文章