Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to open all child nodes using jsTree

Posted on 2013-06-23
5
Medium Priority
?
10,936 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…
Suggested Courses

610 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