JQGrid - 多选

发布于 2024-10-02 04:33:45 字数 100 浏览 0 评论 0原文

JQGrid 中的多选仅允许多项选择或单一选择,并且移位功能不是我期望移位选择执行的功能。我也不喜欢我们需要具有多选功能的组合框。

我还可以使用什么其他解决方案进行多选?

Multiselect in JQGrid only allows either multiple selection or single selections and the shift functionality isn't what I'd expect the shift select to do. I also don't like that we need comboboxes with multiselect.

What other solution could I use for multiselect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2024-10-09 04:33:45

[2011 年 10 月] 更新为使用 4.0 API,更正了班次选择错误,简化了选择循环。在 4.2.0 中测试。


如果像我一样,您需要在 jqgrid 中进行适当的多选 - 其中 ctrl 一次选择一行,选择选择多行,既不清除选择又选择 1 行 - 您已经找到了。

首先要做的事情:在网格定义中设置multiselect: true(我没有设置任何其他多选选项)

下一步:中gridComplete: function () {} set grid.jqGrid('hideCol', 'cb'); - 如果您不需要复选框,则会隐藏它们。

最后:主要部分

beforeSelectRow: function (rowid, e) {
    if (!e.ctrlKey && !e.shiftKey) {
        $("#grid").jqGrid('resetSelection');
    }
    else if (e.shiftKey) {
        var initialRowSelect = $("#grid").jqGrid('getGridParam', 'selrow');
        $("#grid").jqGrid('resetSelection');

        var CurrentSelectIndex = $("#grid").jqGrid('getInd', rowid);
        var InitialSelectIndex = $("#grid").jqGrid('getInd', initialRowSelect);
        var startID = "";
        var endID = "";
        if (CurrentSelectIndex > InitialSelectIndex) {
            startID = initialRowSelect;
            endID = rowid;
        }
        else {
            startID = rowid;
            endID = initialRowSelect;
        }

        var shouldSelectRow = false;
        $.each($("#grid").getDataIDs(), function(_, id){
            if ((shouldSelectRow = id == startID || shouldSelectRow)){
              $("#grid").jqGrid('setSelection', id, false);
            }
            return id != endID;                        
        });
    }
    return true;
}

结束 - 希望有帮助

[Oct 2011] Updated to use 4.0 API, corrected shift-selection bugs, simplified selection loop. Tested in 4.2.0.


If like me, you needed a proper multiselect in the jqgrid - where ctrl selects a single row at a time, select selects multiple rows and neither clear the selection and selects 1 row - You've found it.

First things first: set multiselect: true in the grid definition (I didn't set any other multiselect options)

Next: In gridComplete: function () {} set grid.jqGrid('hideCol', 'cb'); - this hides the checkboxes if you don't want them.

Finally: The main part

beforeSelectRow: function (rowid, e) {
    if (!e.ctrlKey && !e.shiftKey) {
        $("#grid").jqGrid('resetSelection');
    }
    else if (e.shiftKey) {
        var initialRowSelect = $("#grid").jqGrid('getGridParam', 'selrow');
        $("#grid").jqGrid('resetSelection');

        var CurrentSelectIndex = $("#grid").jqGrid('getInd', rowid);
        var InitialSelectIndex = $("#grid").jqGrid('getInd', initialRowSelect);
        var startID = "";
        var endID = "";
        if (CurrentSelectIndex > InitialSelectIndex) {
            startID = initialRowSelect;
            endID = rowid;
        }
        else {
            startID = rowid;
            endID = initialRowSelect;
        }

        var shouldSelectRow = false;
        $.each($("#grid").getDataIDs(), function(_, id){
            if ((shouldSelectRow = id == startID || shouldSelectRow)){
              $("#grid").jqGrid('setSelection', id, false);
            }
            return id != endID;                        
        });
    }
    return true;
}

The End - Hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文