jqgrid:多选和禁用检查(条件) [英] jqgrid: multiselect and disable check (conditional)

查看:16
本文介绍了jqgrid:多选和禁用检查(条件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我喜欢 jqGrid,但有时事情似乎比应有的复杂.
我想要实现的是在每一行上都有一个复选框,以便用户可以选择要提交/处理的行.
不过,我需要阻止一些复选框,因为用户可能没有对该特定行的授权.


I love jqGrid but sometimes things seem more complicated than they should be.
What I would like to achieve is to have a checkbox on each row so that a user can choose which rows are going to be submitted/processed.
I need, though, to block some checkboxes cause the user has no authorization on that particular row, maybe.

我尝试设置 multiselect: true 然后我尝试隐藏复选框:

I've tried to set multiselect: true and then I've tried to hide the checkbox:

loadComplete: function (data) {
    if (data.rows.length > 0) {
        for (var i = 0; i < data.rows.length; i++) {
            if (data.rows[i].cell[7] == 'false') {
                $("#jqg_OrdersGrid_" + data.rows[i].id).css("visibility", "hidden");
            }
        }
    }
},

它运行良好,但仍然 .jqGrid('getGridParam', 'selarrrow') 给我选择的行,即使它们没有被检查.
有没有其他方法可以启用/禁用复选框以及知道哪些复选框已被选中?

and it works well but, still, .jqGrid('getGridParam', 'selarrrow') give me the selected rows, even if they haven't been checked.
Is there any other way to have checkboxes which are enabled/disabled and a way to know which ones have been checked?

谢谢

推荐答案

我建议你禁用一些关于禁用"属性可选择的复选框.要全面实施,您需要

I would suggest you to disable some checkboxed from the be selectable with respect of "disabled" attribute. To make full implementation you will need

  1. loadComplete 事件句柄中设置禁用"
  2. 另外防止在 beforeSelectRow 事件句柄中选择禁用的行
  3. 要在多选列的标题中支持全选"复选框,请实现 onSelectAll 事件句柄,以修复禁用行的选择.
  1. set "disabled" inside of loadComplete event handle
  2. additionally prevent selection of disabled rows inside beforeSelectRow event handle
  3. to have support of "select all" checkbox in the header of the multiselect column implement onSelectAll event handle which fix selection of disabled rows.

您可以在这里看到相应的演示.代码最重要的部分在这里:

The corresponding demo can you see here. The most important part of the code is here:

var grid = $("#list10"), i;
grid.jqGrid({
    //...
    loadComplete: function() {
        // we make all even rows "protected", so that will be not selectable
        var cbs = $("tr.jqgrow > td > input.cbox:even", grid[0]);
        cbs.attr("disabled", "disabled");
    },
    beforeSelectRow: function(rowid, e) {
        var cbsdis = $("tr#"+rowid+".jqgrow > td > input.cbox:disabled", grid[0]);
        if (cbsdis.length === 0) {
            return true;    // allow select the row
        } else {
            return false;   // not allow select the row
        }
    },
    onSelectAll: function(aRowids,status) {
        if (status) {
            // uncheck "protected" rows
            var cbs = $("tr.jqgrow > td > input.cbox:disabled", grid[0]);
            cbs.removeAttr("checked");

            //modify the selarrrow parameter
            grid[0].p.selarrrow = grid.find("tr.jqgrow:has(td > input.cbox:checked)")
                .map(function() { return this.id; }) // convert to set of ids
                .get(); // convert to instance of Array
        }
    }
);

更新: 免费 jqGrid 支持 hasMultiselectCheckBox 回调,可用于为 jqGrid 的所有行创建多选复选框.可以使用 rowattr 来另外禁用某些行.结果,人们将以更简单的方式获得上述功能.对于带有本地数据(datatype: "local"loadonce: true)的免费 jqGrid,建议另外使用 multiPageSelection: true 选项.multiPageSelection: true 选项将在分页时保存数组 selarrrow.它允许通过在selarrrow 中填充相应的 id 来预选"某些行.请参阅答案更新部分和答案演示 了解更多信息.

UPDATED: Free jqGrid supports hasMultiselectCheckBox callback, which can be used to create multiselect checkboxes not for all rows of jqGrid. One can use rowattr to disable some rows additionally. As the result one will get the described above functionality in more simple way. It's recommended to use multiPageSelection: true option additionally for free jqGrid with local data (datatype: "local" or loadonce: true). The option multiPageSelection: true will hold the array selarrrow on paging. It allows "pre-select" some rows by filling the corresponding ids inselarrrow. See UPDATED part of the answer and the answer with the demo for additional information.

这篇关于jqgrid:多选和禁用检查(条件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆