Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding all nodes in dijit.Tree

Tags:

dojo

Is there a good way to expand/close all the expandable nodes in a dijit.Tree?

For those looking for an answer, put this in your initializing code:

var treeControl = new dijit.Tree({
    model: treeModel,
    expandAll: function() {
        // summary:
        //     Expand all nodes in the tree
        // returns:
        //     Deferred that fires when all nodes have expanded

        var _this = this;

        function expand(node) {
            _this._expandNode(node);

            var childBranches = dojo.filter(node.getChildren() || [], function(node) {
                return node.isExpandable;
            });

            var def = new dojo.Deferred();
            defs = dojo.map(childBranches, expand);
        }
        return expand(this.rootNode);
    }
});

At least, that works for me. And you can do the same with collapseAll() where you only need to switch _this._expandNode(node); with _this._collapseNode(node);

like image 216
peirix Avatar asked Dec 23 '22 06:12

peirix


1 Answers

Yes, autoExpand=true (as an initialization parameter to the Tree).

If you need to expand/collapse dynamically, Tree used to have a method for that, but I took it out. However, you can copy it from: http://bugs.dojotoolkit.org/changeset/20529.

like image 195
Bill Keese Avatar answered Jan 02 '23 15:01

Bill Keese