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

后端 未结 3 1916
轻奢々
轻奢々 2020-12-17 02:25

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 sho

相关标签:
3条回答
  • 2020-12-17 02:56

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

    See the demo.

    0 讨论(0)
  • 2020-12-17 02:57
    $('#jqxGrid').jqxGrid({
        groupsexpandedbydefault: true
    });
    

    worked like a charm for me (source).

    0 讨论(0)
  • 2020-12-17 03:19
    $('#grid-expand-collapse').change(function () {
    
        var idPrefix = "MyGridghead_", index, length, tarspan;
        var groups = $(options.gridElement)[0].p.groupingView.sortnames[0];
    
        if ($(this).is(':checked')) {
    
            for (index = 0, length = groups.length; index < length; index++) {
    
                tarspan = $("#MyGridghead_" + index + " span." + "tree-wrap-" + $(options.gridElement)[0].p.direction);
                    if (!tarspan.hasClass($(options.gridElement)[0].p.groupingView.minusicon)) {
                        $(options.gridElement).jqGrid('groupingToggle', 'MyGridghead_' + index);
                    }
            }
        }
        else {
            for (index = 0, length = groups.length; index < length; index++) {
    
                tarspan = $("#MyGridghead_" + index + " span." + "tree-wrap-" + $(options.gridElement)[0].p.direction);
                if (tarspan.hasClass($(options.gridElement)[0].p.groupingView.minusicon)) {
                    $(options.gridElement).jqGrid('groupingToggle', 'MyGridghead_' + index);
                }
            }
        }
    
    });
    
    0 讨论(0)
提交回复
热议问题