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

Sort Child Nodes Relative to Parent

1 Answer 87 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 2
Craig asked on 20 Nov 2015, 04:20 PM

Hi,

 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:

http://www.telerik.com/forums/how-to-sort-child-nodes-of-a-node

&

http://www.telerik.com/support/kb/aspnet-ajax/details/sorting-treenodes

 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,

Craig

 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">
<Columns>
    <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">
        <ItemTemplate>
            <asp:CheckBox ID="cboxExplicitInclude" runat="server" AutoPostBack="true" OnCheckedChanged="cboxExplicitInclude_CheckedChanged" />
         </ItemTemplate>
    </telerik:TreeListTemplateColumn>
    <telerik:TreeListTemplateColumn HeaderText="Exclude" HeaderStyle-Width="50px" ItemStyle-Width="50px">
        <ItemTemplate>
            <asp:CheckBox ID="cboxExplicitExclude" runat="server" AutoPostBack="true" OnCheckedChanged="cboxExplicitExclude_CheckedChanged" />
         </ItemTemplate>
    </telerik:TreeListTemplateColumn>
</Columns>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" ScrollHeight="520px" />
    </ClientSettings>
</telerik:RadTreeList>

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 25 Nov 2015, 12:45 PM
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.

Regards,
Viktor Tachev
Telerik
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
Tags
TreeList
Asked by
Craig
Top achievements
Rank 2
Answers by
Viktor Tachev
Telerik team
Share this question
or