expand particular node in dojo tree

4.2k Views Asked by At

I have three nodes in the tree and would like to keep the first node expanded, is there a way in dojo tree which would support this?

Thanks.

2

There are 2 best solutions below

2
On BEST ANSWER

If you have id of the node that you want to expand. you can expand that node as follows - myTree will be your tree and expandNodeId is the id of the node you want to expand.

var nodes = myTree.getNodesByItem(expandNodeId);

if(!nodes[0].isExpanded){
     myTree._expandNode(nodes[0]);
}
0
On

In the above case the expandNodeId is the ID that you assigned to the node that was clicked. So, in your onClick() function you can do something like this;

            var theTree = new Tree({
                model: myModel,
                onClick: function(item, node){

                    // auto-expand the node when clicked
                    var nodes = that.theTree.getNodesByItem(item.id);
                    if(!nodes[0].isExpanded)
                        theTree._expandNode(nodes[0]);

                }
            });