Opening all nodes to a certain point in the hierarchy.

4,485 views
Skip to first unread message

andrew_scfc

unread,
Jun 29, 2010, 7:29:17 AM6/29/10
to jsTree
Hi,

I have successfully built a tree view using JSON. I am trying to close
all the nodes down from a certain point. I believe you are supposed to
use closeall and so far I have been able to get this to work to close
all nodes:

$("#demo1").jstree("open_all");

I however want to close nodes from one particular node down; something
like:
$("#demo1").jstree("open_all", "Node 4");

This doesn't work for me and I'd be very grateful if someone could
provide me some example code to achieve the effect I want:

- Node1 (open)
- Node 2 (open)
- Node 3 (open)
-Node 4 (closed)
- ... all below closed

Cheers

vakata

unread,
Jun 29, 2010, 8:03:48 AM6/29/10
to jsTree
open_all and close_all have a first argument which is a selector /
jquery object / DOM node inside the tree.

So you can use for example:
$("#demo1").jstree("open_all", "#some-node-id");
or:
$("#demo1").jstree("close_all", "#some-node-id");

You can use both functions to achieve various effects.

Kindest regards,
Ivan

andrew_scfc

unread,
Jun 30, 2010, 4:05:36 AM6/30/10
to jsTree
Thanks for your time Ivan.

How do I know the ID of elements generated from JSON script? When I
view the source it does not show the generated DOM elements.

Thanks
Andy
> > Cheers- Hide quoted text -
>
> - Show quoted text -

vakata

unread,
Jun 30, 2010, 4:56:21 AM6/30/10
to jsTree
For debugging use a tool like firebug/dragonfly/integrated debugger in
ie8

Kindest regards,
Ivan

raimon

unread,
Jul 1, 2010, 5:06:54 AM7/1/10
to jsTree
And using new version 1.0? how could i open a node from a certain
item?

On 30 Juny, 10:56, vakata <ivan.bozha...@gmail.com> wrote:
> For debugging use a tool like firebug/dragonfly/integrated debugger in
> ie8
>
> Kindest regards,
> Ivan
>
> On 30 Юни, 11:05, andrew_scfc <andrew_s...@yahoo.co.uk> wrote:
>
>
>
> > Thanks for your time Ivan.
>
> > How do I know the ID of elements generated from JSON script? When I
> > view the source it does not show the generated DOM elements.
>
> > Thanks
> > Andy
>
> > On 29 June, 13:03, vakata <ivan.bozha...@gmail.com> wrote:
>
> > > open_all and close_all have a first argument which is a selector /
> > > jquery object / DOMnodeinside the tree.
>
> > > So you can use for example:
> > > $("#demo1").jstree("open_all", "#some-node-id");
> > > or:
> > > $("#demo1").jstree("close_all", "#some-node-id");
>
> > > You can use both functions to achieve various effects.
>
> > > Kindest regards,
> > > Ivan
>
> > > On 29 Юни, 14:29, andrew_scfc <andrew_s...@yahoo.co.uk> wrote:
>
> > > > Hi,
>
> > > > I have successfully built a tree view using JSON. I am trying to close
> > > > all the nodes down from a certain point. I believe you are supposed to
> > > > use closeall and so far I have been able to get this to work to close
> > > > all nodes:
>
> > > > $("#demo1").jstree("open_all");
>
> > > > I however want to close nodes from one particularnodedown; something
> > > > like:
> > > > $("#demo1").jstree("open_all", "Node4");
>
> > > > This doesn't work for me and I'd be very grateful if someone could
> > > > provide me some example code to achieve the effect I want:
>
> > > > - Node1 (open)
> > > >    -Node2 (open)
> > > >       -Node3 (open)
> > > >          -Node4 (closed)
> > > >             - ... all below closed
>
> > > > Cheers- Hide quoted text -
>
> > > - Show quoted text -- Amaga el text entre cometes -
>
> - Mostra el text citat -

vakata

unread,
Jul 1, 2010, 5:15:19 AM7/1/10
to jsTree
I am not sure I get your question. Sorry :(
What do you need to do - if it is open a node with code:

$("#tree").jstree("open_node","#node-id"); // for example :)

Cheers,
Ivan

raimon

unread,
Jul 6, 2010, 7:47:53 AM7/6/10
to jsTree
Sorry about my english....

I will try to explain with and example:
I have an HTML tree:

<div id="funciones">
<ul>
<li id="1" rel="N1" >...</li>
<ul>
<li id="11" rel="N2" >...</li>
<ul>
<li id="111" rel="N3" >...</li>

and when the tree is loaded, i want to make visible the item with
id=111 (so, the 3th level item)
If i do:
jQuery("#funciones").jstree("open_node", "#11");
it is not "visible" because its father (id=1) is not opened.
So i must do
jQuery("#funciones").jstree("open_node", "#1");
jQuery("#funciones").jstree("open_node", "#11");
and it works.

But there is not a way to open all the hierarchy with just 1 function?
like "open_hierarchy", or "open_all_nodes"?

Thanks!!





On 1 Jul, 11:15, vakata <ivan.bozha...@gmail.com> wrote:
> I am not sure I get your question. Sorry :(
> What do you need to do - if it isopenanodewith code:
>
> $("#tree").jstree("open_node","#node-id"); // for example :)
>
> Cheers,
> Ivan
>
> On 1 Юли, 12:06, raimon <raimonarde...@hotmail.com> wrote:
>
>
>
> > And using new version 1.0? how could iopenanodefrom a certain
> > > - Mostra el text citat -- Amaga el text entre cometes -

vakata

unread,
Jul 7, 2010, 12:41:27 PM7/7/10
to jsTree
I just added a fix for this in my working copy. I will commit in few
minutes and then you can use the updated version. Until then you can
simply do this:

$("#11").parentsUntil(".jstree",".jstree-
closed").andSelf().each(function ()
{ jQuery("#funciones").jstree("open_node", this); });

Cheers,
Ivan

peelman

unread,
Apr 6, 2011, 5:29:08 PM4/6/11
to jst...@googlegroups.com
Did this make into the commit and is it available now in the current version?  If so what is the name of the method that does this?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages