Solved

How to open all child nodes using jsTree

Posted on 2013-06-23
5
9,572 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to read data from SQL server  to sharepoint 2013 ? 3 25
Html CheckBox obtain Its Value 5 27
Insert Button on a table 16 37
ajax to record click 3 16
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.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

840 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