How can we expand the tree to maximum 3 levels down on loading

3,675 views
Skip to first unread message

Olivier Grimard

unread,
Mar 9, 2011, 12:19:49 PM3/9/11
to jsTree
I've got my initial tree populated by a JSON/Ajax call just fine but I
want to expand all nodes to a specific level.
For example, I would like to be able to expand my tree to maximum 3
levels down on loading

Any suggestions or example?
Thanks.
-Olivier

mvwd

unread,
Mar 15, 2011, 8:00:29 AM3/15/11
to jsTree
.bind('loaded.jstree', function(e, data){
/**
* Open nodes on load (until x'th level)
*/
var depth = 3;
data.inst.get_container().find('li').each(function(i) {
if(data.inst.get_path($(this)).length<=depth){
data.inst.open_node($(this));
}
});
})

...maybe there are more elegant and faster ways to do that, but this
should work.
Markus.

ragche

unread,
Nov 22, 2013, 5:26:26 AM11/22/13
to jst...@googlegroups.com
works great.  If you are using jquery, just use this with out $.
Reply all
Reply to author
Forward
0 new messages