Hi,
Sorry if this is an obvious question but im still learning GoJS (which is great btw)
so my question is how can i collapse all nodes when doubleclicking on one of them ?
I want to be have only one expanded node at all time
here is my code :
go.Node, {
selectionAdorned: false,
isTreeExpanded: false,
doubleClick: (e, node) => {
let cmd = myTreeLocal.commandHandler;
if (!node.isTreeLeaf) {
if (!node.isTreeExpanded) {
if (!cmd.canExpandTree(node)) return;
cmd.expandTree(node);
NetworkActions.requestNetworkbyId(node.Zd.dataKey);
}
} else {
}
}
},
When you say you only want at most one node to be expanded, are you not including the root node? I’ll assume that’s the case and that you want to show three levels of the tree (root, children, and grandchildren) but you only want to show the grandchildren of at most one child node.
I suggest that you do something like:
myDiagram.nodeTemplate =
$(go.Node, . . .,
{
isTreeExpanded: false,
doubleClick: function(e, node) {
var diag = e.diagram;
if (node.isTreeExpanded) {
diag.commandHandler.collapseTree(node);
} else {
diag.startTransaction("expand subtree");
// collapse everything down to two levels
diag.findTreeRoots().each(function(r) { r.collapseTree(2); });
// but then expand this particular node
diag.commandHandler.expandTree(node);
diag.commitTransaction("expand subtree");
}
}
},
. . .