How do I expand all and collapse all using dynatree?

codeChris picture codeChris · Jan 30, 2013 · Viewed 8.9k times · Source

I am using dynatree and would like to have "open all" and "close all" links above the tree. How do I do this using a link?

Thanks in advance.

Answer

gilly3 picture gilly3 · Jan 31, 2013

There's an example of expanding all nodes in the documentation. Use the .visit() method and call .expand() on each node:

$("#tree").dynatree("getRoot").visit(function(node){
    node.expand(true);
});

Pass false to collapse each node.