Don't allow parent selection

9 posts, 0 answers
  1. Dan Harvey
    Dan Harvey avatar
    67 posts
    Member since:
    Jul 2008

    Posted 15 Nov 2013 Link to this post

    Hello,

    I am using a RadDropDownTree control.  And my items look like this:

     

    1. Statements
            -Allocations
            -Tax
    2.Other
            -Other Reports
            -Tax Estimates

    I want to prevent the user from selecting the parent items.  In the above example, that would be the "Statements" and "Other".  I want users to be able to only select the children.

    Another issue i am having is on child selection, the control does not collapse it's dropdown.

    Any idea on how to achieve this?

    Thanks,

     

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

    Posted 18 Nov 2013 Link to this post

    Hi Dan Harvey,

    Please have a look into the following code snippet to select only the child nodes of RadDropDownTree. The default behavior of RadDropDowntree is that it will not collapse the DropDown after selecting the Entry. You can explicitly collapse the DropDown by using closeDropDown().

    ASPX:
    <telerik:RadDropDownTree ID="RadDropDownTree" runat="server" DataSourceID="SqlDataSource1"
        DataFieldID="id" DataFieldParentID="parentid" DataTextField="text" DefaultMessage="Choose a value"
        OnClientEntryAdding="OnClientEntryAdding" ExpandNodeOnSingleClick="true">
    </telerik:RadDropDownTree>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [id], [text], [parentid] FROM [Details]">
    </asp:SqlDataSource>

    JavaScript:
    <script type="text/javascript">
        function OnClientEntryAdding(sender, args) {
            var path = args.get_entry().get_fullPath();
            var s = path.split("/");
            if (s.length == 1) {
                // if the selected entry is parent then it will not allow to select
                args.set_cancel(true);
            }
            else {
                // close the dropdown explicitly
                sender.closeDropDown();
            }
        }
    </script>

    Hope this will helps you.
    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan Harvey
    Dan Harvey avatar
    67 posts
    Member since:
    Jul 2008

    Posted 19 Nov 2013 Link to this post

    Shinu,

    This is exactly what I needed.  Thank you.
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 28 Apr 2014 Link to this post

    Hi,

    You could also access the embedded tree and handle its node clicking event. I am sending you a sample project for a reference.

    Regards,
    Peter Filipov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Nathan
    Nathan avatar
    4 posts
    Member since:
    Nov 2013

    Posted 17 Oct 2014 Link to this post

    Thanks for the nudge in the right direction.  I have an update to suggest.  The example appears to only work if you have two levels to your tree.  This example checks the selected node and ask "Do you have any children".

    function rtAddRejectReasons_EntryAdding(sender, args) {
        var item = sender.get_embeddedTree().findNodeByText(args.get_entry().get_text());
        if (item._hasChildren() == true) {
            //The node has children
            args.set_cancel(true);
        }
        else {
            //The node does not have children
            sender.closeDropDown();
        }      
    }
  7. DuelingCats
    DuelingCats avatar
    49 posts
    Member since:
    Jul 2012

    Posted 21 Apr 2015 Link to this post

    Nathan's solution is what I came to this thread for, but I reworked it a bit to use functions that are documented and are not considered private.

    function DropDown_EntryAdding(sender, args) {
        var node = sender.get_embeddedTree().findNodeByText(args.get_entry().get_text());
         
        //get_allNodes returns all child nodes of a Node.
        if (node.get_allNodes().length > 0) {
            //This node has children
            args.set_cancel(true);
        } else {
            //This node does not have children
            sender.closeDropDown();
        }  
    }

     

  8. John
    John avatar
    8 posts
    Member since:
    Aug 2015

    Posted 28 Aug 2015 in reply to Shinu Link to this post

    Just a comment. The set_cancel(true) doesn't work if you have check boxes enabled. I'm trying to find a way to prevent parent check boxes from being checked.
  9. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 02 Sep 2015 Link to this post

    Hi John,

    I am not quite sure about your case. Could you please elaborate a bit? Which type of checkboxes you are using? 

    Regards,
    Peter Filipov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Crackneo
    Crackneo avatar
    1 posts
    Member since:
    Sep 2010

    Posted 27 Oct in reply to Shinu Link to this post

    Gracias, también eres lo que necesitaba

     

     

     

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