Reputation: 186
The recent integration of jsTree on my page has been a great success, despite my inability to open a single node from code. I start with an empty div in a jQueryUi dialog and a tree on it. When the user clicks on buttons, it opens the dialog and create the HTML for the tree in the variable "registerHTML". Then I use this code
$( "#registerTree" ).jstree().destroy();
$( "#registerTree" ).html(registerHTML);
$('#registerTree').bind("loaded.jstree", function () {
$('#registerTree').jstree('open_all');
});
$( "#registerTree" ).jstree({
"checkbox" : {
"keep_selected_style" : false
},
"plugins" : [ "checkbox" ]
});
Because I reload the dialog for every button clicked, I destroy the tree than recreate it completly. I read in previous questions that it was better to put the bind() or on() function before before setting jstree(). I don't understand why it wouldn't work and tried a lot of manners. Note that I have the checkbox plugin functional.
Thanks a lot!
Upvotes: 0
Views: 2046
Reputation: 1052
To open all the node in your tree after the tree is completely loaded bind for the ready.jstree event.
$('#registerTree').bind("ready.jstree", function () {
$('#registerTree').jstree('open_all');
}).jstree();
ready event is triggered after all nodes are finished loading in your tree.
Given an example in JSBIN - Link
Upvotes: 3