Sort Child Nodes Relative to Parent

2 posts, 0 answers
  1. Craig
    Craig avatar
    10 posts
    Member since:
    Jan 2015

    Posted 20 Nov 2015 Link to this post


     I have a RadTreeList each node has a sort order that comes from the database, that is relative to the parent. (Sort order is part of the object the RadTreeList is bound to).  How can I sort the RadTreeList using this sort order? Simply using an 'ORDER BY' clause on the Database query doesn't work because the sort order isn't universal for the tree it's only relative to it's parent. I want to sort the children of each individual node. 

     I saw these help article relating to the RadTreeView:


     Does it work similarly for the RadTreeList - can I write a compare class that compares the sort order of the two given TreeListDataItems and it will work? (Hasn't so far for me, but I could be missing something). Is there any way to implement this simply by manipulating the entries for the ParentDataKeyNames/DataKeyNames or adding multiple entries? I tried making the DataKeyNames Sort Order, but that fails to bind.

    I basically just want to use the Sort Order to sort all child nodes of each particular node, instead of just sorting by DataKeyName (AttributeId in this case). 

    Thanks much,


     If it helps here is the RadTreeList in question.

    <telerik:RadTreeList ID="rtlCopsAttributes" runat="server" OnNeedDataSource="rtlCopsAttributes_NeedDataSource" AutoGenerateColumns="false"
        ParentDataKeyNames="ParentId" DataKeyNames="AttributeId" AllowMultiItemSelection="true" AllowPaging="false" AllowSorting="false"
        OnItemDataBound="rtlCopsAttributes_ItemDataBound" Height="800px" Width="500px" AllowRecursiveSelection="true" AllowRecursiveDelete="true">
        <telerik:TreeListBoundColumn DataField="AttributeId" UniqueName="AttributeId" HeaderText="Id" Display="false" />
        <telerik:TreeListBoundColumn DataField="SortOrder" UniqueName="SortOrder" HeaderText="Sort Order" Display="false" />
        <telerik:TreeListBoundColumn DataField="Description" UniqueName="Description" HeaderText="Description" Display="false" />
        <telerik:TreeListBoundColumn DataField="ParentName" UniqueName="ParentName" HeaderText="Parent Name" Display="false" />
        <telerik:TreeListCheckBoxColumn DataField="HasChildren" UniqueName="HasChildren" HeaderText="Has Children" Display="false" />
        <telerik:TreeListCheckBoxColumn DataField="IsRequired" UniqueName="IsRequired" HeaderText="Is Required" Display="false"/>                                                                        
        <telerik:TreeListBoundColumn DataField="ParentId" UniqueName="ParentId" HeaderText="Parent Id" Display="false" />
        <telerik:TreeListBoundColumn DataField="Name" UniqueName="AttributeName" HeaderText="Name" />
        <telerik:TreeListCheckBoxColumn DataField="IsDefault" UniqueName="IsDefault" HeaderText="Default" HeaderStyle-Width="50px" ItemStyle-Width="50px" />
        <telerik:TreeListTemplateColumn HeaderText="Include" HeaderStyle-Width="50px" ItemStyle-Width="50px">
                <asp:CheckBox ID="cboxExplicitInclude" runat="server" AutoPostBack="true" OnCheckedChanged="cboxExplicitInclude_CheckedChanged" />
        <telerik:TreeListTemplateColumn HeaderText="Exclude" HeaderStyle-Width="50px" ItemStyle-Width="50px">
                <asp:CheckBox ID="cboxExplicitExclude" runat="server" AutoPostBack="true" OnCheckedChanged="cboxExplicitExclude_CheckedChanged" />
            <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" ScrollHeight="520px" />


  2. Viktor Tachev
    Viktor Tachev avatar
    1438 posts

    Posted 25 Nov 2015 Link to this post

    Hi Craig,

    If you would like to have custom sort order of the child items you would need to use custom logic. One approach you can use is to build a custom comparator and use it to sort all items that have the same parent.

    Another approach you can go for is to enable load on demand for the RadTreeList control. With this option the child items are requested only after the user clicks on the expand/collapse button of an item. The child items are populated in the OnChildItemsDataBind event. You can use that event to retrieve the child items for the currently expanded parent and sort them according to your requirements.

    Viktor Tachev
    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
  3. DevCraft R3 2016 release webinar banner
Back to Top