Wednesday 8 February 2012

How to change the sort order in the editor tree

One of the questions I've been asked by a couple of clients now is whether there is a way to sort the items that appear in the editor tree.

I've recently been asked about one of the sites which is used to advertise cars. In the CMS there is a page called "a list of cars for sale" and underneath that we create "a car for sale". Rather than creating each new car at the bottom of the list, they want to be able to group the cars around registration date. The reason for this is to make it much easier to maintain. If you have 50 cars in a list, it's not easy to manage.

Forgive me that I'm not able to post the actual full code, but I'll do my best to point you in the right direction. It turns out the solution is quite simple. In the "a list of cars for sale" page, you can override the Children property like so:


        public override System.Collections.Generic.IList<ContentItem> Children
        {
            get
            {
                // for each of your children, cast it to a CarForSalePage and sort them with LINQ
                // then return the list cast back to a list of content items
            }
        }

Using this method you really have a powerful tool at your disposal for cutomising the editor. If.. (if!) I ever get time I'd like to fork the code and look at being able to customise this in the admin tool.

Hope this helps!