Highlighting the selected node on loading the tree

757 views
Skip to first unread message

Akshay

unread,
Jul 14, 2009, 9:52:12 AM7/14/09
to jsTree
Ivan,

I've been using the jsTree 0.9.6 and I pass some node ID's to the
'opened' & 'selected' params to open/select the tree/node when it
loads initially. However, the 'selected' doesn't seem to highlight the
node (it doesn't add the class="clicked") to that node. I have a
custom theme we created for use in our website which almost entirely
mimicks the default theme but this isn't a theme issue. I tried to add
a $(nodeId).find("a").addClass("clicked"); to the onopen callback
which does highlight the node but then it persists (i.e. the node
won't unhighlight when I click on other nodes)

please advise

Thanks
akshay

vakata

unread,
Jul 15, 2009, 5:23:34 AM7/15/09
to jsTree
Hi,

using addClass("clicked") will only make the node appear selected but
in the internals it is not marked as selected - use .select_branch()
instead.
As for your problem - I really cannot tell - why don't you upgrade to
0.9.8 (or just wait a few days for 0.9.9)?

Regards,
Ivan

Akshay

unread,
Jul 21, 2009, 12:48:12 PM7/21/09
to jsTree
Ivan,

should the .select_branch be called in the onload or onopen callbacks?
I use async loading for the tree and do not set the children attribute
in the JSON.
Also, if the node doesn't have children, I set the 'state' attribute
to empty(see the 2nd node in the JSON below).
[{attributes: { id: '123'},state: 'closed',data: 'xyz',},{attributes:
{id: '456'},state:'',data: 'pqr'}]
So the idea is to load the children on clicking the node, but if there
are no children to the node it should not show the closed/opened icons
next to it.
I observed that if I set the state to 'open' the node ID passed in
'selected' gets highlighted but the open icons appear next to all the
nodes.


--
Akshay

vakata

unread,
Jul 22, 2009, 6:44:58 AM7/22/09
to jsTree
Try losing the 'state' attribute altogether when there are no
children. Again I urge you to use the latest version.
As for the callbacks - use the onload callback, although I am not sure
that it is even implemented in 0.9.6!

Regards,
Ivan

Akshay

unread,
Jul 23, 2009, 12:43:38 PM7/23/09
to jsTree
Ivan,

Got the latest version but that doesn't solve my problem. The node ID
specified in 'selected' doesn't get highlighted on loading. Also I
observed that if I try to use onload callback to do the selection on
load it never gets called since the onopen callback fires first. If I
add the node selection logic to to the onopen callback it messes up
with the node selection by mouseclick. And yes, I have removed the
'state' attribute when there are no children.

--
Akshay

Richard

unread,
Jul 23, 2009, 1:22:54 PM7/23/09
to jsTree
Hey Akshay,

I'm obviously not Ivan, but I thought I throw an idea out which may be
helpful. If your using async mode you might want to do your bindings
inside of:
___________________________________

$(window).ajaxComplete(function(){
//bind stuff here
});
___________________________________

Ofcoarse you'll want to put that inside of your $(document).ready
(function(){. I'm not certain this will fix your problem, but it's
commonly used to bind things that have been added/injected into DOM
after the document has loaded.

Good luck,

Richard

vakata

unread,
Jul 27, 2009, 3:09:22 AM7/27/09
to jsTree
Well, then could you provide a working example, so that I can help you
debug. Because I cannot reproduce the problem. I can assure there have
been no known problems with selected/opened in the latest version.

Kindest regards,
Ivan

Akshay

unread,
Jul 30, 2009, 6:05:59 PM7/30/09
to jsTree
unfortunately I cannot show a working example.

However the good part is I managed to get over this issue. Had to
modify the code in the open_branch slightly (where we check for the
hasClass('leaf')) and then modified my onselect callback too. This
worked both in 0.9.6 & 0.9.8

Richard's suggestion wouldn't have worked in my case since I didn't
want to do anything after the ajax request completed

Thanks for your help and suggestions though

--
Akshay
Reply all
Reply to author
Forward
0 new messages