Copied to clipboard

Flag this post as spam?

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


  • Chad 65 posts 129 karma points c-trib
    Dec 22, 2009 @ 05:17
    Chad
    0

    Extending the Umbraco Ultimate Picker to Sort

    Hi Guys,

    I'm using Umbraco 4.0.3, and on the website I am using the Ultimate Picker to list a big checkbox list of about 250 odd items. The issue is that these are not in alphabetical order - so it's a nightmare for the client to find which ones need to be checked. To be clear, I'm talking about the client UI side of things, that a client will use when actually using the picker.

    I'm digging around the source, there is an 'addListControlNode' method, which takes an 'umbraco.cms.businesslogic.Content' paramater and iterates through the Children property and add items to the CheckboxList control. I have no idea if it's possible to sort this type of object.

    So I'm thinking I have two options. I can loop through the Children property, and build up my own list of the elements and then sort them with an applicable algorithm (sounds messy). OR I can use XPath pieces and the methods in the umbraco.library namespace (GetXmlNodeByID..etc).. and sort then using XPath. This second option would require a fair bit more of a code change and I'm trying to get this out the door ASAP.

    Any thoughts or insights?

     

  • Chad 65 posts 129 karma points c-trib
    Dec 22, 2009 @ 05:26
    Chad
    0

    .. Wait.. I'm a noob... linq to the rescue..

    foreach (CMSNode child in node.Children.OrderBy(x => x.Text))

    Hrm, not quite perfect though, because the parent node I am using contains sub nodes, and it's sorting each of the subnodes independently....

  • Chad 65 posts 129 karma points c-trib
    Dec 22, 2009 @ 05:41
    Chad
    0

    So now, after all the items have been added to the ListItem collection, I am just sorting that using a handy little extension method.

     

        public static class Extensions{

    public static void Sort(this ListItemCollection items) {
    IList<ListItem> itemList = new List<ListItem>();

    foreach (ListItem item in items) {
    itemList.Add(item);
    }

    IEnumerable<ListItem> itemEnum = itemList.OrderBy(x => x.Text);

    items.Clear();

    items.AddRange(itemEnum.ToArray());


    }
    }
Please Sign in or register to post replies

Write your reply to:

Draft