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

Recursive selection children only

2 Answers 55 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
miro mrazik
Top achievements
Rank 1
miro mrazik asked on 02 Aug 2012, 12:41 PM
Greetings,

I have a problem with recursive selection. Treelist selects recursively whole branch of selected node (all its ancestors and descendants). This behavior is pretty "unconfortable" for me. If my nodes are folders and files and I select a subfolder and I want to delete it with it contents for example then I cerainly don't want to delete its parent folder (or any of its ancestors) so I would like to ask if there is any way how to make treelist to recursively select only descendant nodes of selected item.

Thanks in advance
Miro 

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 07 Aug 2012, 09:26 AM
Hello Miro,

Instead of recursive selection, you can manually select the children of a given item.
<ClientSettings Selecting-AllowItemSelection="true">
    <ClientEvents OnItemSelected="ItemSelected" OnItemDeselected="ItemDeselected" />
</ClientSettings>

<script type="text/javascript">
    function ItemSelected(sender, args) {
        var item = args.get_item();
        var childItems = item.get_childItems();
        for (var i = 0; i < childItems.length; i++) {
            childItems[i].set_selected(true);
        }
    }
 
    function ItemDeselected(sender, args) {
        var item = args.get_item();
        var childItems = item.get_childItems();
        for (var i = 0; i < childItems.length; i++) {
            childItems[i].set_selected(false);
        }
    }
</script>


However, this can only be done for already expanded items. Non-visible children will not be selected, unless you extend the custom logic to check for not selected children of an item after it is expanded.

Kind regards,
Tsvetina
the Telerik team
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 their blog feed now.
0
Priya
Top achievements
Rank 1
answered on 25 Dec 2012, 06:17 PM
Hi ,
Thanks for your code, it works when the nodes are already expanded i.e. parent and child all are visible, but it does not work when the view is collapsed (at initial load). evn if I select the parent and expand the node the children are not selected and this is because children are not created at initial load and they are created when we expand the node for the first time.
Please let me know if you have any solution for this. Thanks in advance.
Tags
TreeList
Asked by
miro mrazik
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Priya
Top achievements
Rank 1
Share this question
or