Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Custom sort for Sitecore items (backend)

Modified: 2008/10/28 14:20 by Vincevanm - Categorized as: Sitecore
Example: I want to order my news items in the Content Tree by a (custom) Sitecore field named "News date". The "sort subitems" function in the Sitecore backend does not allow this. Two steps are needed to accomplish this. The first is creating a icomparer class and the second is adding it to Sitecore.

Image

Example sorting code

namespace Evident.Web.Classes
{
    public class NewsSort : Sitecore.Data.Comparers.Comparer
    {

        protected override int DoCompare(Item itemFirst, Item itemSecond)
        {

         return itemFirst.Fields"Datum".Value.CompareTo(itemSecond.Fields"Datum".Value);


        }
   
        
        
    }


}

Create a new "Child Sorting Rule"
Adding custom sort

Adding custom sort

Navigate to: \sitecore\system\settings\subitem sorting Right click the node and choose 'insert from template'. Choose the "Child sorting" template from \sitecore\templates\system\ Insert the DLL reference here: MyNamespace.MyType,MyAssembly (.dll)

Notes

Also check: http://sdn5.sitecore.net/Scrapbook/Understanding%20the%20Sort%20Order.aspx

 © Evident Interactive BV