This is a migrated thread and some comments may be shown as answers.

How to load treeview nodes on-demand

2 Answers 392 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Thai
Top achievements
Rank 1
Thai asked on 21 Dec 2011, 04:30 AM
Hi,

I want to do this:
For example, I have a treeview with one node "Root":
+ Root

Then when I expand this node, I will send a request to server and get child nodes of node "Root", and append to it.

But currently, if a node have no child nodes, the expand icon is not showed and the expand event is not fired, so I cannot do anythings further.

are there any ways that I can do that?

Thanks!
Thai

2 Answers, 1 is accepted

Sort by
0
Karl Mikesell
Top achievements
Rank 1
answered on 26 Apr 2012, 08:47 PM
The workaround here is to always add a child node 'Loading. . .' collasped, the expand event will remove this node and add actual data on demand.

This results in the expended node appearing with "Loading. . ." the brief moment it takes to request data. 
0
Christopher
Top achievements
Rank 1
answered on 30 May 2012, 02:05 AM
The trick of always adding a "Loading..." node to an empty displayed node works to force the "expand/collapse" arrow to show up,
I use this, then when I click to expand, I populate the node by appending to it.
But each of the new ligit children I also have to add a "Loading...." node under each of them to get their expand/collapse arrow to show up,.
After adding this new "Loading ..." node I call collapse on the node.
I have an example with 3 such children. The first two does properly collapse the node but the
arrow shown is the southeast arrow, not the east arrow. Clicking on such arrows
gives me the behavior of an east arrow, ie it does the expand.
So the southeast arrow is inconsistent with its behavior of "expand' (what I want).
My 3rd child displays correctly with an east arrow.
Is there some kind of "refresh" command I can call to force redispkay?

Another way this problem could be solved is if append didn't automatically expand the
node being appended to. Having another arg to append to stop this auto-expansiion would
in general be a good capability.
We really need 3 different arrows:
- expand (like now)
- collapse (like now)
- expand but there were no children when this node was rendered, so likely there are none now.
 (shows as a grayed east arrow, or, probably better, an east arrow that has its outline in black and center in white.
 (because gray indicates "disabled")

Another way to fix this problem is to be able to turn off the "auto hiding" of the expand/collapse arrow
when a node has no children, ie always show expand/collapse arrow.
 I'd want to declare this for the whole tree, but maybe someone would
want to customize this per node.

I'm using chrome browser v 19 and Windows 7.
Tags
TreeView
Asked by
Thai
Top achievements
Rank 1
Answers by
Karl Mikesell
Top achievements
Rank 1
Christopher
Top achievements
Rank 1
Share this question
or