Why doesn't jsTree open_all() work for me?
You have to hook into the events, and then call open_all
.
To have all nodes open on load, use:
var tree = $("#id-or-selector-for-my-tree-element"); tree.bind("loaded.jstree", function (event, data) { tree.jstree("open_all"); });
Do the above, before you initialize the tree with .jstree({...})
.
If you refresh it, then to have all nodes open again, you have to use:
tree.bind("refresh.jstree", function (event, data) { tree.jstree("open_all"); });
Yes, this is an old question, but with no accepted answer and having the only answer not being useful to me, here's my answer which I now use:
var tree = $("td#modelXML") .bind("loaded.jstree", function (e, data) { data.inst.open_all(-1); // -1 opens all nodes in the container }) .jstree({ /* your jsTree options as normal */ });
The key point here is that data.inst
is your jsTree
, and is the only reference you will have available because tree
won't have a value until .jstree({
finishes. Since loaded.jstree
is called within the .jstree({
call, the result will not yet exist. See?
I was completely unable to get it to work either with tree.jstree('open_all')
or data.inst.open_all(-1)
- in the end I had to use data.instance.open_all()
- notice the change from inst to instance, and open_all(-1) to just open_all() - both of those seem to be required with jQuery 1.11 and jstree 3.0.0. My final code block looks like this:
$(document).ready(function() { var tree = $('#jstree'); tree.bind('loaded.jstree', function(event, data) { data.instance.open_all(); }); tree.jstree({});});