Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 954 karma points
    Oct 31, 2011 @ 04:44
    Tom
    0

    OrderBy not working in 4.7.1

    Hi All,

    try as I might I can't get order by to work... I'm trying to order on a datetime desc but having no luck at all..

    Cheers,

    Tom

     

     

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var displayType = PageData[0];
        var events = Model.NodeById(1109).Children.OrderBy("dateTime desc");
    
        if(events.Any()) {
            <section id="events">
            @foreach (var currentEvent in events) {
                var eventDateTime = currentEvent.dateTime;
                <article>
                    <header><h3>@currentEvent.title</h3></header>
                    <time datetime="@eventDateTime.ToString("yyyy-MM-ddTHH:mm")Z">@eventDateTime.ToString()</time>
                    @if(!string.IsNullOrEmpty(currentEvent.location.ToString())) {
                        <section>
                            <h4>Location</h4>
                            @currentEvent.location
                        </section>
                    }
    
                    @if(!string.IsNullOrEmpty(currentEvent.description.ToString())) {
                        <section>
                        @currentEvent.description
                        </section>
                    }
            </article>
            }
            </section>
        }
    }   

     

  • Owen 123 posts 246 karma points
    Oct 31, 2011 @ 07:12
    Owen
    0

    In 4.7 there is a bug with OrderBy(descending) function, and it's fixed in 4.7.1 as they said.

    http://umbraco.codeplex.com/workitem/30198

    Here is a alternative you can use to list node in descending:

    http://www.uwebzone.com/blogs/umbraco/how-to-sort-node-descending-with-razor-macro.aspx

  • Tom 713 posts 954 karma points
    Nov 01, 2011 @ 01:00
    Tom
    0

    Hi Owen,

    unfortunately it is not fixed in 4.7.1

    i ended up using

    var events = new DynamicNode(1109).GetChildrenAsList.Items.OrderByDescending((dynamic dn) => dn.dateTime);

    to get around it

Please Sign in or register to post replies

Write your reply to:

Draft