How to order elements in container by custom property?

Topics: General
Feb 26, 2012 at 10:36 PM

I create a new Content Type called "Event" and add DateTimeField (from Gallery) called "When" to it. Then I create a list of Events.

Now I can't understand how to order this list by "When" property.

Quickly view through source I found this hard-coded options: 

<select id="@Html.FieldIdFor(m => m.Part.Record.OrderByProperty)" name="@Html.FieldNameFor(m => m.Part.Record.OrderByProperty)">
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "CommonPart.CreatedUtc", T("Date Created").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "CommonPart.PublishedUtc", T("Date Published").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "TitlePart.Title", T("Title").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "RoutePart.Title", T("Routable Title").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "RoutePart.Slug", T("Slug").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "CustomPropertiesPart.CustomOne", T("Custom 1").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "CustomPropertiesPart.CustomTwo", T("Custom 2").Text)
    @Html.SelectOption(Model.Part.Record.OrderByProperty, "CustomPropertiesPart.CustomThree", T("Custom 3").Text)
</select>
So, how can I can order by my property? Should I write a new module or what?
Thanks.

 

Coordinator
Feb 26, 2012 at 10:39 PM

If using lists, you can only sort by a few things such as creation date. If you want to sort by arbitrary criteria, use Projector, a new feature in Orchard 1.4, which is due next Wednesday.

Feb 27, 2012 at 6:13 AM
Edited Feb 27, 2012 at 6:36 AM

Thank you. Any chance to use Projector now?

Coordinator
Feb 27, 2012 at 6:41 AM

Sure, just clone the repository and sync to the latest in 1.x.

Feb 27, 2012 at 7:05 AM

Oh, silly me. New both to Orchard and mercurial. Now i get it. Thanks.