We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid: how to "customize" the sorting on a column?

Thread ID:





127649 Nov 30,2016 10:17 AM UTC Dec 5,2016 01:21 AM UTC UWP 3
Tags: SfDataGrid
Pierre-Christophe DUS
Asked On November 30, 2016 10:17 AM UTC


I would like to know if there is a way to customize the sorting on a column?

I encounter a problem on a column that is binded to a object, which is built on strings and numbers: the format is like string - number1 - number2

So the ordering doesn't take into account the value of the numbers, as the the object is a string:
Column sorting

=> But is it possible to "customize" the sorting process to respect the object format?


Jai Ganesh S [Syncfusion]
Replied On December 1, 2016 12:33 PM UTC

Hi Pierre, 
We have prepared a sample for applying the custom sorting for a column and its working fine in our end and please use your logic to this comparer for sort the column. 
this.sfGrid.SortComparers.Add(new SortComparer() { Comparer = new CustomComparer(), PropertyName = "Name" }); 
public class CustomComparer : IComparer<object>, ISortDirection 
    private ListSortDirection _SortDirection; 
    public ListSortDirection SortDirection 
        get { return _SortDirection; } 
        set { _SortDirection = value; } 
    public int Compare(object x, object y) 
        int namX; 
        int namY; 
        //While data object passed to comparer 
        if (x.GetType() == typeof(UserInfo)) 
            namX = ((UserInfo)x).Name.Length; 
            namY = ((UserInfo)y).Name.Length; 
        //While sorting groups 
        else if (x.GetType() == typeof(Group)) 
            //Calculating the group key length 
            namX = ((Group)x).Key.ToString().Length; 
            namY = ((Group)y).Key.ToString().Length; 
            namX = x.ToString().Length; 
            namY = y.ToString().Length; 
        //returns the comparison result based in SortDirection. 
        if (namX.CompareTo(namY) > 0) 
            return SortDirection == ListSortDirection.Ascending ? 1 : -1; 
        else if (namX.CompareTo(namY) == -1) 
            return SortDirection == ListSortDirection.Ascending ? -1 : 1; 
            return 0; 
Jai Ganesh S 

Pierre-Christophe DUS
Replied On December 2, 2016 10:59 AM UTC

Thank you I've solved my issue.

Jai Ganesh S [Syncfusion]
Replied On December 5, 2016 01:21 AM UTC

Hi Pierre, 
Thank you for the update. 
Please let us know if you need further assistance in this. 
Jai Ganesh S 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon