Link to home
Start Free TrialLog in
Avatar of WestCoast_BC
WestCoast_BCFlag for Canada

asked on

How to open all child nodes using jsTree

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
Avatar of Jagadishwor Dulal
Jagadishwor Dulal
Flag of Nepal image

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of WestCoast_BC
WestCoast_BC
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WestCoast_BC

ASKER

The code that I submitted in my last comment solved my problem
My code that I submitted solved my problem
Avatar of Khaled webdev
Khaled webdev

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