Solved

How to open all child nodes using jsTree

Posted on 2013-06-23
5
10,158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

705 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