Copied to clipboard

Flag this post as spam?

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


  • Douglas Ludlow 210 posts 366 karma points
    Jan 25, 2012 @ 20:20
    Douglas Ludlow
    0

    DataType Grid Sorting

    I know that drag and drop sorting has been proposed for uComponents v4 (and I'm really looking forward to it), but how about just regular sorting, it doesn't appear to be working for me.

    I would expect that the order specified using Content Sort Priority and Content Sort Order in the datatype would be used to not only sort the data for the user in the editor, but also sort the data in the xml that's outputted. Am I wrong in assuming this? Why have sorting options at all, if the xml isn't sorted....?

    Anyhow, if my assumption is wrong, any ideas as to how I can sort DynamicXml using Razor?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 31, 2012 @ 14:49
    Lee Kelleher
    0

    Hi Douglas,

    Replied on your other thread about this.  Any input, suggestions you have can be added to the workitem up on CodePlex, I'm sure Ove (DTG developer) would love the feedback!

    Thanks, Lee.

  • Daniel Larsen 116 posts 381 karma points
    Feb 20, 2012 @ 13:55
    Daniel Larsen
    0

    Hi, is there a way to sort DynamicXml using Razor?

    Thanks :-)

  • Douglas Ludlow 210 posts 366 karma points
    Feb 20, 2012 @ 14:56
    Douglas Ludlow
    0

    There isn't, unfortunately. The only workaround I was able to come up with was to iterate through the DynamicXml and store it all in a list of generic objects, then sort from there. The following example sorts training classes stored in the DataType Grid by date, then writes them out grouped by month:

    @if (Model.classes.GetType() == typeof(DynamicXml) && Model.classes.Count() > 0)
    {
        List<dynamic> classes = new List<dynamic>();
        
        foreach (dynamic c in Model.classes)
        {
            DateTime date = DateTime.Now;
            // If the date is blank, use today's date.
            
            try
            {
                date = Convert.ToDateTime(c.date.InnerText);
            }
            catch {}
            
            string month = date.ToString("MMMM");
            
            var training = new {
                Date = date,
                Month = month,
                Title = c.title.InnerText,
                Link = c.link.InnerText,
                Instructor = new {
                    Name = c.instructor.InnerText,
                    Link = c.instructorLink.InnerText
                },
                Location = c.location.InnerText
            };

            classes.Add(training);
        }

        classes.Sort((x, y) => DateTime.Compare(x.Date, y.Date));
        string currentMonth = classes.First().Month;
        
        <h4>@currentMonth</h4>
        <ul>
        @foreach (var c in classes)
        {
            if (c.Month != currentMonth)
            {
                currentMonth = c.Month;
                
                @Html.Raw("</ul>");
                <h4>@currentMonth</h4>                  
                @Html.Raw("<ul>");
            }
            
            <li>
                @c.Date.ToString("MM-dd-yyyy") | <a href="@c.Link">@c.Title</a> | @c.Location | <a href="@c.Instructor.Link">@c.Instructor.Name</a>
            </li>
        }
        </ul>
    }

    Hope you find this helpful!

  • Daniel Larsen 116 posts 381 karma points
    Feb 20, 2012 @ 15:14
    Daniel Larsen
    0

    Thank you very much!

  • Chen 39 posts 68 karma points
    Feb 26, 2013 @ 18:26
    Chen
    0

    I'm currently experiencing sorting issues with DataType Grid. The arrows seem to do nothing, and the list (11 items) displayed in my content node are in the following) order: 10, 11, 1, 2, 3, 4, ...... 9. 

    uComponenets version: 5.4.0

    umbraco version: 4.11.4

     

    Also had UI issues (js error in the back office - image resizer) when I had DAMP picker installed. After I uninstalled DAMP the UI issue was gone.

     

Please Sign in or register to post replies

Write your reply to:

Draft