bind open_node to close all other open node branches

5,637 views
Skip to first unread message

Scott Conklin

unread,
Oct 6, 2010, 9:34:18 PM10/6/10
to jsTree
I am new to jstree (and jquery for that matter.) i have poured over
the documentation and the samples and i cannot figure out how to
collapse all other root nodes on the open of another root node.
i am using the 1.0 version and i have come across this example in
another post, but I believe this only works in the older version?? is
this correct? ( i cannot get any callback functions to work in the
1.0 version)

onopen : function (NODE,TREE_OBJ) {
$(NODE).parent().children("li.open").not(NODE).each(function () {
TREE_OBJ.close_branch(this, true); // The second param TRUE is
dsisabling the close animation
});

I believe i need to accomplish what i want by using this style below?
is that correct ? But i do not know how to implement the function to
do what i need

$("#tree1").bind("open_node.jstree", function (event, data) {
?
})

can someone help with how to do that?

(also where can i get more documentation on what is passed in
'data'.? )

vakata

unread,
Oct 12, 2010, 4:35:45 PM10/12/10
to jsTree
Hi,

This is the code you need:

$("#tree1").bind("open_node.jstree", function (event, data) {
data.rslt.obj.siblings(".jstree-open").each(function ()
{ data.inst.close_node(this, true); });
});

This will work on all levels, to make it work only for root nodes:

$("#tree1").bind("open_node.jstree", function (event, data) {
if(data.inst._get_parent(data.rslt.obj) == -1) {
data.rslt.obj.siblings(".jstree-open").each(function ()
{ data.inst.close_node(this, true); });
}
});

Kindest regards,
Ivan

Anil Kumar

unread,
Mar 18, 2014, 11:09:27 AM3/18/14
to jst...@googlegroups.com
Hi Ivan,
I am trying to achieve this functionality in latest jsTree  3.0.0 version.But this sample code is not working(object not found error) or i am missing something.Please advise.
Along with this if you could guide me how to restrict to open full tree in case of any of the selected child node.Currently if any of the child node is Checked full tree till that node is getting opened.I am achieving this by Close-All property but while Refreshing the tree its getting opened again for all selected child node. 


Thanks 

Ivan Bozhanov

unread,
Mar 18, 2014, 11:22:00 AM3/18/14
to jst...@googlegroups.com
You should adapt this to the new parameters in 3.0 (there is no obj param).

$("#tree1").bind("open_node.jstree", function (event, data) {
  var obj =  data.instance.get_node(data.node, true);
  if(obj) {
     obj.siblings('.jstree-open").each(function () { data.instance.close_node(this, 0); });
  }
});
Use core.expand_selected_onload - set it to false - it won't open the tree when it is first loaded. As for when calling refresh - there is no way to stop this.

Best regards,
Ivan

Prabin Shrestha

unread,
Oct 9, 2015, 7:16:46 AM10/9/15
to jsTree
Thank you Ivan. You saved my day.
Reply all
Reply to author
Forward
0 new messages