+1-888-365-2779
Try Now
More in this section

Forums / Module Builder / Sort Child Items in Parent Widget Template

Sort Child Items in Parent Widget Template

2 posts, 0 answered
  1. Sean
    Sean avatar
    5 posts
    Registered:
    26 Mar 2015
    12 May 2015
    Link to this post

    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?

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    23 Sep 2016
    15 May 2015
    Link to this post
    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
     
2 posts, 0 answered