How to expand/collapse all panels in the diagram programatically?

I want to expand/collapse all panels in the diagram,how can I do it programatically?

Could you provide a simplified template and examples of expanded and collapsed panels?

I assume you have seen the definition and uses of the “PanelExpanderButton”. GoJS Buttons -- Northwoods Software

Assuming your question is duplicated at How to stop the links to the empty space in scrolling table - #7 by walter, I’ll also assume that you have just one “PanelExpanderButton” in your node template.

The Panel must have a name. Then it’s just a matter of:

myDiagram.nodes.each (function(n) {
    var p = n.findObject("PANELNAME");
    if (p !== null) p.visible = false;
myDiagram.commitTransaction("collapsed all panels");