如何限制在 JQGRID 中的 Header Select All 事件上选择特定行

How to restrict particular Row to be selected on Header Select All event in JQGRID(如何限制在 JQGRID 中的 Header Select All 事件上选择特定行)
本文介绍了如何限制在 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.

这篇关于如何限制在 JQGRID 中的 Header Select All 事件上选择特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)