Home - Forums-.NET - FlyTreeView (ASP.NET) - duplicating ExpandLevel functionality clientside

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

duplicating ExpandLevel functionality clientside
Link Posted: 13-Sep-2008 08:20
I am wondering if others have addressed or solved this issue.  On the server side it is easy to expand or collapse a flytreeview to a desired level simply by setting the Expandlevel property.  This method however requires a trip back to the server if you want to provide the user with a control (i.e. button) on the rendered page that triggers this event.  A client-side approach provides a better user experience (for my app at least).  My javascript experience is minimal.  Has anyone written any code (that they are willing to share) that duplicates setting the expandlevel client-side.

Thank you
Link Posted: 14-Sep-2008 22:32
Do you really need to use ExpandLevel at client-side?
There's node.expand() client-side method.
Anyway, you can try to create a recursive function that uses expand() method to expand required number of levels.
Like this:
function expandNodes(node, level)
{
    var childNodes = node.getChildNodes();
    for(var i = 0; i < childNodes.length; i++)
    {
        var child = childNodes[i];
        child.expand();
        if (level > 1)
        {
            expandNodes(child, level - 1);
        }
    }
}