How do I programmatically select a node in jsTree and open all parents

Viewed 27326

In a multi-level jsTree how do I select a particular node (probably a leaf node) and expand all it's parents? Example:
From this JSFiddle (http://jsfiddle.net/mmeah/fyDE6/) I want to programmatically select Grand Child and have all parent nodes opened.

For some context I'm trying to ensure the user returns to the correct node in the tree if they follow a deep link into my site

3 Answers

jQuery selection doesn't work on nodes that are not opened [expanded] already. Hence I chose to open [expand] all elements before I did the jQuery selection and then close all the nodes after that.

                // open all nodes to select the desired node using jquery.
                $("#tree").jstree('open_all');
                var node = $("desiredNodeSelector");
                // close all tree since we are done with the selection
                $("#tree").jstree('close_all');

Now all we need is just use the 'select_node' jstree api.

$("#tree").jstree('select_node', node);

Related