Sorting Out Sort Order in Sitecore

September 19, 2014

Blog | Development | Sorting Out Sort Order in Sitecore
Sorting Out Sort Order in Sitecore
Sort order is one method Sitecore uses to determine the order of items in the content tree. Generally speaking, the higher an item’s sort order is, the lower it will show up in the tree under its parent.

Standard Fields -

NOTE: The sort order field is located under the Appearance field section. If you can’t see this, you might need to go to the View tab in the ribbon and check off the Standard Fields checkbox.

Let’s a take a deeper look.  As you’re building, you might find that you need to move a field. This should be a simple drag and drop procedure if the items are all part of the same field section. However, if the fields are defined in different places, you may have some maneuvering to do.

If some of the fields are defined on the template for the item, and others are defined on an inherited template, you could refactor templates in such a way that the fields are all defined on the same template. This will allow you to easily drag them into the required order. This might, however, require a big lift. Luckily, there is an alternative.

Kevin Varley, our Director of Technology, recommends using the sort order field to interlace the fields. First, confirm that the same sort order is used on both sections. If not, adjust it and you’ll be able to easily organize the fields in whatever order you want.

Below is an example of a Sitecore Content and Template Tree. In this example, there is a base Tree template defined, which contains a Data section and Leaves, Roots and Description fields. Next, there is a Fruit Tree template, which uses the Tree template as its base. If you look in the main Content area, you’ll find a Lemon Tree content item, which was made with the Fruit Tree template.

Lemon Tree -

The sort order values for all the fields are as follows:

Item Sort Order
Tree.Data 100
Tree.Data.Leaves 100
Tree.Data.Roots 200
Tree.Data.Description 300
Fruit Tree.Data 100
Fruit Tree.Data.Fruit 100

Here, the Lemon Tree item combines the two sets of fields in the Data section and organizes them by their Sort Order. This results in Fruit and Leaves fighting for the “100” Sort Order position. Sitecore, by default, will fall back to ordering the fields alphabetically, which is why the Fruit field appears above the Leaves field.

Our goal, in this instance, is to place the Fruit field between the Leaves and Roots fields.

Lemon Tree 2 -

Since both data field sections had a sort order of 100, we need to modify the Sort Order on the Leaves field to 50. This forces Sitecore to organize items numerically instead of alphabetically. This results with Leaves at the top of the list. The remainder of the fields needn’t be changed as their sort orders already give us the desired outcome.

Mission accomplished! We reached our goal without a complete refactoring of template definitions.  Ifyou have questions about this tutorial, or want to request a certain topic, reach out to us @Geekhive!

Tino DeRico, Developer, GeekHive

Tino DeRico

  • Sitecore
  • Tutorial
subscribe to GeekHive's newsletter

Never miss out on a Sitecore update again!

Our newsletter features a blog roundup of our top posts so you can stay up to date with industry trends, tutorials, and best practices.

Recent Work

Check out what else we've been working on