Get Selected Node

9 posts, 1 answers
  1. César
    César avatar
    14 posts
    Member since:
    Sep 2013

    Posted 29 Nov 2013 Link to this post

    Hi,

    Is there any method that retrieves the SelectedNode object from the RadDropDrownTree object? 

    Regards
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Nov 2013 Link to this post

    Hi César ,

    The Client side method get_entries() will return all the selected RadDropDownTree Entries Collection. Another methods get_selectedValue() and get_selectedText() will return the value/text of an entry or a collection of entries separated by semicolon. Please have a look into the sample code snippet.

    ASPX:
    <telerik:RadDropDownTree ID="RadDropDownTree1" runat="server" DataSourceID="SqlDataSource1"
        DataFieldID="id" DataFieldParentID="parentid" DataTextField="text" CheckBoxes="SingleCheck">
    </telerik:RadDropDownTree>
    <telerik:RadButton ID="RadButton1" runat="server" Text="GetSelectedNode" AutoPostBack="false"
        OnClientClicked="OnClientClicked1">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked1(sender, args) {
            var tree = $find("<%=RadDropDownTree1.ClientID %>");
            //DropDownTree Entries Collection
            var entries = tree.get_entries();
            // get the selected text
            alert("Selected Text :" + tree.get_selectedText());
        }
    </script>

    Hope this will helps you.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. César
    César avatar
    14 posts
    Member since:
    Sep 2013

    Posted 02 Dec 2013 Link to this post

    Hi,

    Thanks for your response, I had already seen those methods but I'm afraid they are not useful for my case.

    I am looking to retrieve an specific attribute for the node object (in client side): the level of the selected node. 

    Which would be the best way to do this?

    Thanks

  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Dec 2013 Link to this post

    Hi César,

    Please have a look into the following code snippet to get the level of the selected node of RadDropDownTree.

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked1(sender, args) {
            var tree = $find("<%=RadDropDownTree1.ClientID %>");
            alert("Level :" + tree.get_embeddedTree().get_selectedNode().get_index());
        }
    </script>

    Thanks,
    Shinu.
  6. César
    César avatar
    14 posts
    Member since:
    Sep 2013

    Posted 02 Dec 2013 Link to this post

    Hi,

    Thanks for your response. Your example works. I also found that you can retrieve the selected node from the "eventArgs" object in the OnClientEntryAdded event:

    OnClientEntryAdded="onEntryAdded"

    function onEntryAdded(sender, eventArgs) {
        var selectedNode = eventArgs.get_entry();
    }


    The point now is that "get_index()" does not retrieve the level (sorry for mixing two topics here):

    ElementA (Level 0) (Index 0)
    SubElement (Level 1) (Index 0)

    ElementB (Level 0(Index 1)
    SubElementB  (Level 1(Index 1)
    SubElementFromSubElementB (Level 1(Index 1)


    Do I need to write a function that iterates the parent nodes to get the Level?

    Regards
  7. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 05 Dec 2013 Link to this post

    Hello,

    An easy and convenient way of getting the selected node level in the OnClientEntryAdded would be:
    //markup code
    <telerik:RadDropDownTree ID="RadDropDownTree1" runat="server" DefaultMessage="Select location" Skin="Default" OnClientEntryAdded="onEntryAdded"
        EnableFiltering="true" FilterSettings-Highlight="Matches">
    </telerik:RadDropDownTree>
    //JavaScript
    function onEntryAdded(sender, eventArgs) {
        //finds the text value of the entry
        var entryText = eventArgs.get_entry().get_text();
        //gets the embedded tree object
        var embeddedTree = sender.get_embeddedTree();
        //find the node object based on the entry text ( it is actually the node's text)
        var entyNode = embeddedTree.findNodeByText(entryText);
        //gets the node level
        alert(entyNode.get_level());
    }



    Regards,
    Boyan Dimitrov
    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.
  8. César
    César avatar
    14 posts
    Member since:
    Sep 2013

    Posted 05 Dec 2013 Link to this post

    Thanks. 

    This answer covers all the topic.


    Regards
  9. Prahlad
    Prahlad avatar
    3 posts
    Member since:
    Mar 2015

    Posted 27 Mar 2015 Link to this post

    hii

    can any one tell me how to expend the node if i select the child node then only that root node will be expend instead of other nodes.
  10. Ivan Danchev
    Admin
    Ivan Danchev avatar
    835 posts

    Posted 01 Apr 2015 Link to this post

    Hello,

    To achieve that you can access the RadTreeView embedded in the RadDropDownTree and add the following OnClientNodeExpanding event handler:
    protected void Page_Load(object sender, EventArgs e)
    {
     
        RadTreeView tree = RadDropDownTree1.EmbeddedTree;
        tree.OnClientNodeExpanding = "OnClientNodeExpanding";
     
        tree.NodeClick += tree_NodeClick;
    }

    function OnClientNodeExpanding(sender, args) {
        var node = args.get_node();
        var tree = node.get_treeView();
        var nodes = tree.get_allNodes();
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].get_nodes() != null) {
                nodes[i].collapse();
            }
        }
    }

    And then
    Regards,
    Ivan Danchev
    Telerik
     

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

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