Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  31] [ 1]  / answers: 1 / hits: 27757  / 12 Years ago, fri, august 17, 2012, 12:00:00

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


More From » jquery

 Answers
23

jsTree gives an open_node() function to arbitrarily trigger any node to open. Just scan the tree for non-open parents and open them.



Example:
http://jsfiddle.net/mmeah/yyy8W/



$(#findChild).click(function(){
$.jstree._reference(myTree).open_node(#Node_001,function(){;},false);
});
$(#findGrandChild).click(function(){
var closedParents = $(#Node_003).parents(li.jstree-closed);
for(var i=closedParents.length-1;i>=0;i--){
pleaseOpen($(closedParents[i]));
}
});

function pleaseOpen(thisNode){
if(typeof thisNode==undefined) return;
if(thisNode.hasClass(jstree-leaf) || thisNode.hasClass(jstree-open) ) return;
$.jstree._reference(myTree).open_node(thisNode,function(){;},true);
}



[#83568] Thursday, August 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
braydon questions
Tue, Nov 23, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 4 Years ago
Fri, May 15, 20, 00:00, 4 Years ago
Fri, Mar 27, 20, 00:00, 4 Years ago
;