varaprakash
varaprakash

Reputation: 487

jqgrid - expand all/collapse all in grouping

Is there a way we can implement expand all/collapse all functionality for grouping feature in jqgrid? As I understand setting groupingCollapse: true, collapses the data but I would like to make it dynamic, may be on the click of +/- icons placed within the grid. Thanks in advance for any suggestions/help...

Upvotes: 1

Views: 9120

Answers (3)

user3458
user3458

Reputation:

This is specific to a particular version of jqgrid, and it expands all layers, but it's so short and sweet, I just can't resist posting it.

function expandAll() {
    $("#myGrid .ui-icon-circlesmall-plus").trigger("click");
}

Upvotes: 1

varaprakash
varaprakash

Reputation: 487

With Oleg's answer/suggestion and Jqgrid4.4.1, here is what I have done. This works when you want to expand/collapse all rows on click of some button...

function expandCollapseGroups(expandAll) {
    var $grid = $("#grid");
    var idPrefix =$grid[0].id + "ghead_0_", trspans;
    var groups =$grid[0].p.groupingView.groups;
    if ($grid[0].p.grouping) {
        for (var index = 0; index < groups.length; index++) {
            if (expandAll) {
                trspans = $("#" + idPrefix + index + " span.tree-wrap-" +$grid[0].p.direction + "." +$grid[0].p.groupingView.plusicon);
            } else {
                trspans = $("#" + idPrefix + index + " span.tree-wrap-" +$grid[0].p.direction + "." +$grid[0].p.groupingView.minusicon);
            }
                if (trspans.length > 0) {
                $grid.jqGrid('groupingToggle', idPrefix + index);
        }   
        }
    } 
}

Upvotes: 0

Oleg
Oleg

Reputation: 221997

I think you will find the answer on your question in the old answer. The main idea of the answer is to use sortnames[0] property of the parameter groupingView of jqGrid. It is an array which elements can be used to constructs the ids of grouping headers and one can use groupingToggle method to collapse or expand the group header. In the way you can expand or collapse of all groups.

Upvotes: 1

Related Questions