Home - Forums-.NET - FlyTreeView (ASP.NET) - On demand populating

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

On demand populating
Link Posted: 07-Jul-2008 10:33
I have a rather strange problem.  The tree I'm building can be quite massive, so I'm trying to use on-demand AJAX loading as much as possible.  As such, a user selects an item to view in a tree, and will end up seeing that node and only nodes on the path up to the root.  Since each parent on the way up to the root has the possibility of having more children, I add an "addition structure" child node, which when clicked, will tell the parent to go fetch the rest of its children.

The way I'm currently doing this is by checking the value of the node and getting its parent, collapsing, clearing all children, setting its populateNodesOnDemand to true, and expanding it again like so:
if (node.getValue() == "hiddenStructure")
        {
            var parent = node.getParent();
            parent.collapse();
            parent.clearChildNodes();
            parent.setPopulateNodesOnDemand(true);
            parent.expand();
        }


This threw a javascript error in the minified js source (although it did achieve the desired effect).  Is there a better way I could do this, or some way to avoid the javascript error?  Thanks
Link Posted: 07-Jul-2008 22:55
Your code looks to be correct, but where do you use it? Some event handler?
Link Posted: 08-Jul-2008 02:12
It is in the javascript node event when the event type is "selected"
Link Posted: 08-Jul-2008 02:20
This can be a reason.
I would try to use window.setTimeout(yourfuncRef, 100); instead of direct calls
to make your collapse/clearChildNodes/.... sequence executed in a separate thread after a small amount of time.

If you provide a simple test page, I can modify it this way and put back here
Link Posted: 08-Jul-2008 03:43
Here is the page I'm working with:








    //node event router
    function nodeEvent(sender, node, type)
    {
        switch (type)
        {
            case "expanded":
                nodeExpanded(sender, node);
                break;
            case "selected":
                nodeSelected(sender, node);
                break;
        }
    }

    //handler for node expanded event
    function nodeExpanded(tree, node)
    {

    }

    //handler for node selected event
    function nodeSelected(tree, node)
    {
        //if hidden structure node, repopulate parent's children
        if (node.getValue() == "hiddenStructure")
        {
            repopulateChildren(node.getParent());
            return;
        }

        var children = node.getChildNodes();
        for (var i = 0; i < children.length; i++)
        {
            if (children[0].getValue() == "hiddenStructure")
            {
                repopulateChildren(node);
                return;
            }
        }
    }

    function repopulateChildren(node)
    {
        node.collapse();
        node.clearChildNodes();
        node.setPopulateNodesOnDemand(true);
        node.expand();
    }




         OnNodeSelected="FlyTreeView_NodeSelected" ContextMenuID="TreeMenu" Style="overflow: hidden" PostBackOnSelect="true"
     OnNodeEventJavascript="nodeEvent">

        
                 Padding="2px;2px;2px;2px;" BorderColor="LightGray" BorderWidth="1px" BorderStyle="Solid" Font-Bold="true"/>
        
    
Link Posted: 08-Jul-2008 07:09
You can replace direct call to repopulateChildren with setTimeout, like:
var parent = node.getParent();
window.setTimeout(function(){ repopulateChildren(parent); }, 200);

Unfortunately I cannot test this code myself, because I do not have external references from your code.
Link Posted: 09-Jul-2008 04:19
That did the trick.  Thanks a lot for the help!