当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠? [英] How can we have global Expand/Collapse for JQGrid when we have rows grouped on some field?

查看:179
本文介绍了当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can we have global Expand/Collapse for JQGrid when we have rows grouped on some field?

在展开时,它应该展开所有组并折叠所有组应折叠。

On expanding, it should expand all groups and on collapsing all groups should be collapsed.

推荐答案

您可以设置 groupCollapse 的默认值jqGrid的 groupingView 参数的属性与设置任何其他默认参数的方式相同:

You can set default value of the groupCollapse property of the groupingView parameter of jqGrid in the same way like you set any other default parameter:

$.extend($.jgrid.defaults, {
    groupingView: {
        groupCollapse: true
    }
});

更新:在评论中进一步解释后,我可以想象在在某些情况下,当所有组将被展开/折叠时,如果组中的任何一个将被展开/折叠,它可以具有行为。

UPDATED: After additional explanation in the comments I can me imagine that in some cases it can has the behavior when all groups will be expanded/collapsed if any from the groups will be expanded/collapsed.

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;
            }
        }
    }
});

参见演示

这篇关于当我们在某些字段上分组行时,如何为JQGrid进行全局展开/折叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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