Expand/Collapse all groups

Hi,
Are there any api or method where i can collapse or expand all the groups in my canvas.
For example : if there are 5 groups and in single button click, I want to expand or collapse all these groups.

Depending on how you want to deal with any nested groups, either:

myDiagram.commit(function(d) {
    d.findTopLevelGroups().each(function(g) { g.collapseSubGraph(); });
});

Or:

myDiagram.commit(function(d) {
    d.nodes.each(function(g) {
       if (g instanceof go.Group) g.collapseSubGraph();
    });
});