Finding and expanding node

2 posts, 0 answers
  1. Jimmy
    Jimmy avatar
    3 posts
    Member since:
    May 2015

    Posted 07 May 2015 Link to this post

    In our system we have a dynamic RedTreeView which is constructed on load and all nodes got a ID.

    I need the treeview to:

    • collapse all other nodes on click
    • find selected node by ID and expand it
    • find selected node by ID and expand it or simply only expand the selected node

     

    Collapsing the entire treeview is easy, but finding the node and expanding it seems to be a hassle.

     

     

    .

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 08 May 2015 Link to this post

    Hello,

    You can achieve that by calling the RadTreeView's findNodeByAttribute() client-side method in the OnClientNodeClicked event handler, as shown in the code snippet below, where we expand the Node with custom attribute NodeID="RootNode2":
    <script type="text/javascript">
        function OnClientNodeClicked(sender, args) {
            var node = sender.findNodeByAttribute("NodeID", "RootNode2");
            node.expand();
        }
    </script>
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientNodeClicked="OnClientNodeClicked">
        <Nodes>
            <telerik:RadTreeNode Text="Mailbox - John Smith" NodeID="RootNode1">
                <Nodes>
                    <telerik:RadTreeNode Text="Calendar">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Contacts">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
            <telerik:RadTreeNode Text="Mailbox - Samuel Conners" NodeID="RootNode2">
                <Nodes>
                    <telerik:RadTreeNode Text="Calendar">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Contacts">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top