Expand all Nodes in LoadOndemand mode

4 posts, 0 answers
  1. Sekhar
    Sekhar avatar
    22 posts
    Member since:
    Dec 2013

    Posted 07 Jan 2014 Link to this post

    Hi,

    I have a RAD tree view where in i am loading only few levels of Hierarcy data. When i click on a parent node it gets the child nodes by making a call to the database. So basically Load on Demand works when i click on a parent node.

    What i want to achieve is expand all parent nodes Programatically from Javascript i.e when i click expandALL it must load all parent nodes child nodes. Basically i want to trigger the onNodeExpand function (which executes on server) from javascript by looping thru all the parent nodes.


    Thanks
    -Sekhar
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Jan 2014 Link to this post

    Hi Sekhar,

    Please have a look into the following code snippet to expand all nodes of RadTreeView on RadButton Click event.

    ASPX:
    <telerik:RadTreeView runat="server" ID="RadTreeView1">
        <Nodes>
            <telerik:RadTreeNode Text="Node1">
                <Nodes>
                    <telerik:RadTreeNode Text="Node1.1">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="node1.2">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
            <telerik:RadTreeNode Text="Node2">
                <Nodes>
                    <telerik:RadTreeNode Text="Node2.1">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="node2.2">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>
    <telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="false" Text="ExpandAll"
        OnClientClicked="OnClientNodeExpanding">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function OnClientNodeExpanding(sender, args) {
            var tree = $find("<%=RadTreeView1.ClientID %>");
            for (var i = 0; i < tree.get_allNodes().length; i++) {
                if (tree.get_allNodes()[i]._hasChildren()) {
                    tree.get_allNodes()[i].expand()
                }
            }
        }
    </script>

    Hope this will helps you.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sekhar
    Sekhar avatar
    22 posts
    Member since:
    Dec 2013

    Posted 08 Jan 2014 Link to this post

    Hi Shinu,

    Thanks for your reply , but this is not what i am looking for, I am looking to expand all the nodes when i populate the tree in load on Demand mode. 

    Lets say i have the following reporting structure.

    A has reportees A1,A2,A3,A4
    and B has B1 , B2, B3 and B4.
    A1 has A11, A12 as child nodes and A12 has A121 as the child node.
    Similarly B2 has B21 and B3 has B31 and B32, while B1 has B311 and B312 as child nodes.

    Initially i will display only A , A1, B, B1.

    when i click on Expand ALL button, i need to get all the child nodes on demand of A1, A12, B2,B3 and B32 and expand the nodes 

    So how do i achieve that.
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 13 Jan 2014 Link to this post

    Hi Sekhar,

    Shinu's suggestion looks suitable for your scenario. However you may have to call this code in the Expand ALL button's click event instead of OnClientNodeExpanding.

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top