Open Nodes On Programatic Select

1,032 views
Skip to first unread message

Byron Cobb

unread,
Aug 3, 2010, 9:33:48 AM8/3/10
to jsTree
I'm using $.jstree._focused().select_node("#" + id);
How do i force the node parents to open - sort of like the search
function?

ChrisR

unread,
Aug 3, 2010, 12:50:51 PM8/3/10
to jsTree
Hi,

You should open direct descendant of the node and then select the
node, you want to be selected. When you are opening node and have set
open_parents to true (which is default), then all parents of the
opened node will be opened too.
So, your code should look like this:
$.jstree._focused().open_node($.jstree._focused().get_parent("#" +
id));

and after this, you could put your code, it means:

$.jstree._focused().select_node("#" + id);

Though, i haven't tested it.

Best regards,
ChrisRaven

Byron Cobb

unread,
Aug 4, 2010, 4:58:02 AM8/4/10
to jsTree
Thanks Chris,

What I did, using your idea, was on my bind select open all unopened
parents of the selected node.

.bind("select_node.jstree", function (e, data) {
data.rslt.obj.parents('.jstree-closed').each(function () {
data.inst.open_node(this);
});
});

$.jstree._focused().open_node($.jstree._focused().get_parent("#" +
id)); Isnt quite right, but it put me on the right track.

Regards,
Byron Cobb.
> > function?- Hide quoted text -
>
> - Show quoted text -

ChrisR

unread,
Aug 4, 2010, 5:12:45 AM8/4/10
to jsTree
I'm glad, that you solved it. As I wrote, I hadn't tested my
version ;)

Best regards,
ChrisRaven
Reply all
Reply to author
Forward
0 new messages