searching nodes in RadTreeView

2 posts, 0 answers
  1. Bassem
    Bassem avatar
    14 posts
    Member since:
    Jul 2012

    Posted 29 Aug 2012 Link to this post

    i'm doing a project where i can search a node withing my treeView my code so far is this:

    function expandAllAncestors(node) {
                if (node.get_expanded() !== true)
                    node.expand();
     
                if (node.get_level() != 0) {
                    expandAllAncestors(node.get_parent());
                }
            }
     
            function SearchClick() {
     
                var search = $get("<%= ApplicationSearchResult.ClientID %>").value;
                var treeView = $find("<%= MainTree.ClientID %>");
                var nodes = treeView.get_allNodes();
                var NextNode = document.getElementById("<%=NextNode.ClientID %>");
                NextNode.style.display = "block";
                for (var i = 0; i < nodes.length; i++) {
                    var node = nodes[i];
                    if (node.get_text() == search) {
                        node.set_selected(true);
                        expandAllAncestors(node);
                        return;
                    }
                }
     
             }
    I need a simple code so when i search the tree for the second time all the opened nodes should be collapsed and only the searched one is expended
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2012 Link to this post

    Hi Bassem,

    Please modify your code as follows to achieve your scenario.

    Javascript:
    <script type="text/javascript">
      function expandAllAncestors(node)
      {
       if (node.get_expanded() !== true)
       node.expand();
       if (node.get_level() != 0)
       {
        expandAllAncestors(node.get_parent());
       }
      }
      function SearchClick()
      {
       var search = $get("<%= ApplicationSearchResult.ClientID %>").value;
       var treeView = $find("<%= MainTree.ClientID %>");
       var nodes = treeView.get_allNodes();
       for (var i = 0; i < nodes.length; i++)
       {
        nodes[i].collapse();
       }
       for (var i = 0; i < nodes.length; i++)
       {
        var node = nodes[i];
        if (node.get_text() == search)
        {
         node.set_selected(true);
         expandAllAncestors(node);
         return;
        }
       }
      }
    </script>

    Hope this helps.

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