Solved

How to open all child nodes using jsTree

Posted on 2013-06-23
5
8,952 Views
Last Modified: 2016-08-23
I am using jsTree to create a tree.  I would like to have all of the child nodes automatically open and expand when a parent node is selected.  Can anyone give me an example of how I can do this?

I am able to bind open_node to my tree but I haven't figured out how to get the ID of the selected node.

	
$("#my_tree").bind("open_node.jstree", function (e, data) {

// how do I get the id of the selected node?
			$.jstree._reference("#my_tree").open_all('#Selected_id');

	});

Open in new window


Thank you for your help
0
Comment
Question by:WestCoast_BC
  • 3
5 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39270123
Try using:
var $treeview = $("#my_tree");
$treeview 
  .jstree(options)
  .on('loaded.jstree', function() {
    $treeview .jstree('open_all');
  });

Open in new window

0
 

Accepted Solution

by:
WestCoast_BC earned 0 total points
ID: 39270268
Thank you for your help.  I have solved my problem by doing the following:

$("#my_tree").bind("open_node.jstree", function (e, data) 
{
	$(data.rslt.obj).find('li').each(function (i) 
	{
       		data.inst.open_node($(this));
	});
});

Open in new window

0
 

Author Comment

by:WestCoast_BC
ID: 39627934
The code that I submitted in my last comment solved my problem
0
 

Author Closing Comment

by:WestCoast_BC
ID: 39638295
My code that I submitted solved my problem
0
 

Expert Comment

by:Khaled webdev
ID: 41766736
I think I have found best solution inspired from the accepted one:

To close all childrens: (tested)

$("#my_tree").bind("close_node.jstree", function (e, data) {
                data.inst.close_all(data.rslt.obj);
                return false;
            })

Open in new window


To open all childrens (not tested yet)
$("#my_tree").bind("close_node.jstree", function (e, data) {
                data.inst.close_all(data.rslt.obj);
                return false;
            })

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now