jQuery JQGrid - 多选

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4186533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:47:56  来源:igfitidea点击:

JQGrid - Multiselect

jqueryjqgridmulti-select

提问by Bob

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.

JQGrid 中的多选只允许多选或单选,而且移位功能不是我希望移位选择能做的。我也不喜欢我们需要多选的组合框。

What other solution could I use for multiselect?

我可以使用哪些其他解决方案进行多选?

回答by Bob

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

[2011 年 10 月]更新为使用 4.0 API,更正了换档选择错误,简化了选择循环。在 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.

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

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

第一件事multiselect: true在网格定义中设置(我没有设置任何其他多选选项)

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

下一页:gridComplete: function () {}设置grid.jqGrid('hideCol', 'cb');-这会隐藏复选框,如果你不希望他们。

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

结束- 希望有所帮助