Sitecore Sortorder vs Subitem Sorting
At Sitecore, I thought the sort order always takes precedence over the sort of subitems. I was under the assumption that it didn't matter what sort of the element's subtype was as long as one of its children had a sort order of 100 and the other had one of 0, which would be displayed first. In a recent project I see the opposite is happening in the content tree. Priority sorting of a sub-item. Is there a way to customize the sort order of sortorder and subitem? I went through my web.config and distinguished it by what I had for a project that worked the way I thought, but I couldn't find anything that popped up to me.
A visualization of what I see in the content tree for a project that appears to give priority to sorting the subtype:
parent - subitem sorting = created
child1 - created = 01012014, sortorder = 100
child2 - created = 02022014, sortorder = 0
source to share
It might be a bug in Sitecore, but it might also work as intended, you might need to contact Sitecore support to see which one.
The child sorting for "Created" points to Sitecore.Data.Comparers.CreatedComparer, Sitecore.Kernel. If you look at the ExtractKey () method in this class, you can see that it does not include the original SortOrder element. Without this, Sitecore will only sort by Date Created.
public override IKey ExtractKey(Item item)
{
Assert.ArgumentNotNull(item, "item");
KeyObj keyObj = new KeyObj()
{
Item = item,
Key = this.GetCreationDate(item)
};
return keyObj;
}
In contrast, you can look at Child Sorting for Updated, which points to Sitecore.Data.Comparers.UpdatedComparer, Sitecore.Kernel. In its ExtractKey () method, you can see that it returns the sort order of the items to get a mixed sort between the updated date and the sort order.
public override IKey ExtractKey(Item item)
{
Assert.ArgumentNotNull(item, "item");
KeyObj keyObj = new KeyObj()
{
Item = item,
Key = item.Statistics.Updated,
Sortorder = item.Appearance.Sortorder
};
return keyObj;
}
source to share
When you specify a custom sorter to be used, it is exactly the same as the code that compares with the item s sorting options.
There should be a comparator System.Collections.Generic.IComparer
, but after that there is no guarantee that the sort order field will be used, or that if used, it will be in ascending or descending order.
I recommend examining the sorter selected for a particular item and using dotPeek to parse the sorter's source code.
When creating custom sorters, it is good practice to extend the Sitecore class Sitecore.Data.Comparers.Comparer
and override the method DoCompare
. It will process the sort order field sequentially and fall back to the method DoCompare
for secondary sorting.
source to share