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

Recursive Selection

3 Answers 126 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 27 May 2012, 11:14 AM
Hi,

I need to implement the recursive selection at this way:
1. Select all parents when the at least one child item was selected.
2. Select all childs when the parent was selected.

When i use "AllowRecursiveSelection=true" the 1st part of the task does not work for me (when deselect one of the child - parent deselects too). If AllowRecursiveSelection is true then "OnItemSelected" and "OnItemDeselected" client events does not fire...
In other way at client side "get_childItems()" return null for the node not expanded before select and "ExpandCollapse" command fires after "OnItemSelected" and "OnItemDeselected"...

I have no idea how to implement this task. Can anybody show the right way to complete this?

Thx.

3 Answers, 1 is accepted

Sort by
0
Venkata
Top achievements
Rank 1
answered on 05 Jun 2012, 08:03 PM
i am also looking for some solution for this scenario, i don't to expand the whole tree to make my custom code works.
0
Tsvetina
Telerik team
answered on 08 Jun 2012, 01:41 PM
Hi,

The two requirements that you describe are in a bit of conflict - if you select every parent item of a selected item (requirement 1), it will also fire the selected event for these parents, leading to all their child items getting selected (requirement 2).
Here follows code for both requirements but if you run both parts at the same time - clicking an item will lead to selecting all children of its root parent item.

<telerik:RadTreeList ID="RadTreeList1" runat="server" AllowPaging="true" PageSize="10"
    AllowMultiItemSelection="true" DataKeyNames="ID" ParentDataKeyNames="ParentID"
     OnNeedDataSource="RadTreeList1_NeedDataSource"
    Skin="Hay" AutoGenerateColumns="false">
    <ClientSettings Selecting-AllowItemSelection="true">
        <ClientEvents OnItemSelected="itemSelected" />
    </ClientSettings>
    <Columns>
        ............
    </Columns>
</telerik:RadTreeList>


function itemSelected(sender, args) {
    var treelist = sender;
    var selectedItem = args.get_item();
    if(selectedItem.get_parentItem())
    treelist.selectItem(selectedItem.get_parentItem());
     //comment out the above line and uncomment the below one to get all child items selected functionality
    //selectChildren(selectedItem);
 
 
    function selectChildren(item) {
        treelist.selectItem(item);
        if (item.get_childItems().length > 0) {
             
            for (var i = 0; i < item.get_childItems().length; i++) {
                selectChildren(item.get_childItems()[i]);
            }
        }
    }
}

I hope this helps.


Greetings,
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:18 PM
Hi Kaushal,
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
Denis
Top achievements
Rank 1
Answers by
Venkata
Top achievements
Rank 1
Tsvetina
Telerik team
Priya
Top achievements
Rank 1
Share this question
or