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

Expand all Nodes in LoadOndemand mode

3 Answers 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Sekhar
Top achievements
Rank 1
Sekhar asked on 07 Jan 2014, 09:29 PM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jan 2014, 04:48 AM
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.
0
Sekhar
Top achievements
Rank 1
answered on 08 Jan 2014, 03:40 PM
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.
0
Hristo Valyavicharski
Telerik team
answered on 13 Jan 2014, 02:47 PM
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.
Tags
TreeView
Asked by
Sekhar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sekhar
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or