This post discusses how you can utilize the Sitecore Rocks Query Analyzer to set the sort order of items in the Sitecore Content Management System.
In Sitecore, items are sorted by their value stored in the Standard Field __Sortorder. Typically, when adding items, Sitecore will separate these values by 100. Then when an item is resorted, Sitecore will determine where it is sorted to, and adjust it’s __Sortorder value accordingly. Usually this means splitting the difference between the sort order values of the items it has been placed in between.
After many sort order changes, it’s possible that Sitecore will find it has run out of integers that it can split, so it will change all of the sort order values of the items to be 100 apart again, still keeping the same relative order.
It’s ok to be negative
One thing I found recently was that the __Sortorder field can contain negative values, and still function properly. You can manually set -5000 in the __Sortorder field on an item, and be fairly confident that it’ll be sorted to the top.
Even if you move an item above one that’s been set with a negative value, Sitecore will use a more negative value to ensure it can keep the order of items in check.
So when is this useful?
Sometimes reordering can be a tedious process, particularly if you have the same structure in multiple places.
Also, clicking and dragging each item, can be time consuming.
So how can you speed up the process?
You can write specific sort order code if you want them all the same. But that will require a build, and will always keep the sort order fixed to the way the code intends, not allowing manual changes later.
Or, if you just want to set it once, you can utilize the inline editing feature of the Sitecore Rocks Query Analyzer result set.
Grab all the items you’re after, displaying the __Sortorder field in the results.
Double click the cells for the items and set them to negative values.
Once that’s done you can refresh the content tree and see your items resorted the way you want them.