Sort Child Items in Parent Widget Template

Posted by Community Admin on 05-Aug-2018 12:32

Sort Child Items in Parent Widget Template

All Replies

Posted by Community Admin on 12-May-2015 00:00

I have the following code listing Child Items within a Parent Widget Template.

<sf:DynamicDetailContainer ID="detailContainer" runat="server">
    <LayoutTemplate>
        <asp:Repeater runat="server" DataSource='<%# Eval("ChildItems") %>'>
        </asp:Repeater>
    </LayoutTemplate>
</sf:DynamicDetailContainer>

I would now like to order the Child Items by a custom property, i.e. SortOrder, with something like the following which calls a helper function (see below)

<sf:DynamicDetailContainer ID="detailContainer" runat="server">
    <LayoutTemplate>
        <asp:Repeater runat="server" DataSource='<%# Helpers.SortOrder(Eval("ChildItems")) %>'>
        </asp:Repeater>
    </LayoutTemplate>
</sf:DynamicDetailContainer>

Using the helper function below, I keep getting the following error " Database mapped field uses different type 'System.Nullable' "

public static IQueryable<DynamicContent> SortOrder(object dynamicContent)
    var collection = (IQueryable<DynamicContent>) dynamicContent;
    return collection
        .OrderBy(x => x.GetValue<int?>("SortOrder"));

 

Am I going along the right lines?

Posted by Community Admin on 15-May-2015 00:00

Hello Sean,

In order to get the value of your custom field of type Number, please use decimal instead of int.

public static IQueryable<DynamicContent> SortOrder(object dynamicContent)
    var collection = (IQueryable<DynamicContent>) dynamicContent;
    return collection
        .OrderBy(x => x.GetValue<decimal?>("SortOrder"));

Can you please give it a try and you should be able to properly get the value and to order the items.

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed