This project is read-only.

Weird 1.8.1 List functionality - a bug? A quirk? Intended?

Topics: Core, Customizing Orchard
Jul 1, 2014 at 9:36 PM
Edited Jul 1, 2014 at 10:18 PM

I just downloaded the Orchard 1.8.1 source code and have been playing around with it. I noticed that if you create a List of content items and give them a custom sort order, it applies correctly if you visit the full page for that list. However, if you display the list as a widget using the Container Widget, it ignores the custom ordering. The container widget seems to have an option for ordering as well, but this also seems to do nothing with lists.

I looked into the code for the Container Widget and the driver looks like this:
protected override DriverResult Display(ContainerWidgetPart part, string displayType, dynamic shapeHelper) {
            return ContentShape(
                () => {
                    var container = _contentManager.Get(part.Record.ContainerId);

                    IContentQuery<ContentItem> query = _contentManager
                        .Join<CommonPartRecord>().Where(cr => cr.Container.Id == container.Id);

                    if (part.Record.ApplyFilter)
                        query = query.Where(part.Record.FilterByProperty, part.Record.FilterByOperator, part.Record.FilterByValue);

                    var pageOfItems = query.Slice(0, part.Record.PageSize).ToList();

                    var list = shapeHelper.List();
                    list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));

                    return shapeHelper.Parts_ContainerWidget(ContentItems: list);
From what I can tell there is nothing in this code to order the List items properly. However, if you add in an additional order by line to the query, it will display the list items as you ordered them, such as:

IContentQuery<ContentItem> query = _contentManager
                    .Join<CommonPartRecord>().Where(cr => cr.Container.Id == container.Id)
                    .Join<ContainablePartRecord>().OrderByDescending(x => x.Position);
So basically, I'm not sure if this is a glitch or just an oversight or if its supposed to work this way. Basically custom list ordering appears to be broken on Container widgets no matter what you do (out of the box) but I'm not sure if adding this order by line is the correct fix - I'm not all that familiar with the Container functionality.

For now I have fixed it by overriding the Container Widget driver in a plugin - not sure if this is the best way to handle it but it works for my isolated situation.

Can someone provide insight into how this is supposed to work and how to order List items in a container widget?