How to load treeview nodes on-demand

3 posts, 0 answers
  1. Thai
    Thai avatar
    9 posts
    Member since:
    Dec 2011

    Posted 20 Dec 2011 Link to this post


    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?

  2. Karl Mikesell
    Karl Mikesell avatar
    55 posts
    Member since:
    May 2010

    Posted 26 Apr 2012 Link to this post

    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. 
  3. Christopher
    Christopher avatar
    10 posts
    Member since:
    Mar 2012

    Posted 29 May 2012 Link to this post

    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.
Back to Top