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

Don't allow parent selection

8 Answers 679 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Dan Harvey
Top achievements
Rank 2
Dan Harvey asked on 15 Nov 2013, 03:39 PM

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,

 

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Nov 2013, 04:41 AM
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
0
Dan Harvey
Top achievements
Rank 2
answered on 19 Nov 2013, 12:54 PM
Shinu,

This is exactly what I needed.  Thank you.
0
Peter Filipov
Telerik team
answered on 28 Apr 2014, 12:17 PM
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.

 
0
Nathan
Top achievements
Rank 1
answered on 17 Oct 2014, 04:50 PM
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();
    }      
}
0
DuelingCats
Top achievements
Rank 2
answered on 21 Apr 2015, 11:49 AM

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();
    }  
}

 

0
John
Top achievements
Rank 1
answered on 28 Aug 2015, 01:58 PM
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.
0
Peter Filipov
Telerik team
answered on 02 Sep 2015, 10:17 AM
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
0
Crackneo
Top achievements
Rank 1
answered on 27 Oct 2016, 07:10 PM

Gracias, tambiƩn eres lo que necesitaba

 

 

 

Tags
DropDownTree
Asked by
Dan Harvey
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Dan Harvey
Top achievements
Rank 2
Peter Filipov
Telerik team
Nathan
Top achievements
Rank 1
DuelingCats
Top achievements
Rank 2
John
Top achievements
Rank 1
Crackneo
Top achievements
Rank 1
Share this question
or