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
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
This is exactly what I needed. Thank you.
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.
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();
}
}
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();
}
}
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
Gracias, tambiƩn eres lo que necesitaba