当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠?

Sur*_*lla 5 javascript jquery jquery-plugins jqgrid

当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠?

在扩展时,它应该扩展所有组,并且在折叠时应该折叠所有组.

Ole*_*leg 3

您可以像设置任何其他默认参数一样设置 jqGrid 参数groupCollapse属性的默认值:groupingView

$.extend($.jgrid.defaults, {
    groupingView: {
        groupCollapse: true
    }
});
Run Code Online (Sandbox Code Playgroud)

更新:在评论中进行额外解释后,我可以想象,在某些情况下,如果组中的任何组将展开/折叠,则所有组都将展开/折叠时,它可能会出现行为。

var $grid = $("#list"), inOnClickGroup = false;

$grid.jqGrid({
    // ... other options
    grouping: true,
    onClickGroup: function (hid) {
        var idPrefix = this.id + "ghead_", id, i, l,
            groups = this.p.groupingView.sortnames[0];

        if (!inOnClickGroup && hid.length > idPrefix.length &&
                hid.substr(0, idPrefix.length) === idPrefix) {
            id = Number(hid.substr(idPrefix.length));
            if (typeof (groups[id]) !== "undefined") {
                inOnClickGroup = true; // set to skip recursion
                for (i = 0, l = groups.length; i < l; i++) {
                    if (i !== id) {
                        $(this).jqGrid('groupingToggle', this.id + 'ghead_' + i);
                    }
                }
                inOnClickGroup = false;
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

请参阅演示