Recursive Selection

4 posts, 0 answers
  1. Denis
    Denis avatar
    2 posts
    Member since:
    May 2012

    Posted 27 May 2012 Link to this post

    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.
  2. Venkata
    Venkata avatar
    1 posts
    Member since:
    May 2012

    Posted 05 Jun 2012 Link to this post

    i am also looking for some solution for this scenario, i don't to expand the whole tree to make my custom code works.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 08 Jun 2012 Link to this post

    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.
  5. Priya
    Priya avatar
    10 posts
    Member since:
    Dec 2012

    Posted 25 Dec 2012 Link to this post

    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.
Back to Top