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. Image for the cookie policy date

GGC Sorting nothing/empty, large, small

Hello,

I use a GridGroupingControl and in my first column in need numbers. I would like to sort this column from above with no number / empty field and than from large to small numbers. Is there a way to do this?

When I now sort with the default setting, than is sequence from large to small and than the empty fields.

Thanks for your support.
BR Thomas

1 Reply

AR Arulpriya Ramalingam Syncfusion Team May 31, 2017 09:55 AM UTC

Hi Thomas, 

Thanks for your interest in Syncfusion products. 

We could able to understand your scenario and created a simple sample as per the reported scenario. In order to keep the empty cells at the top while applying descending sorting, the IComparer interface can be used. By using IComparer.Compare  method, you can customize the comparison of cell values. Please make use of below code and sample, 

Code snippet  
//Form() 
// set columnname to be sorted 
SortColumnDescriptor cd = new SortColumnDescriptor("ID"); 
this.gridGroupingControl1.TableDescriptor.SortedColumns.Add(cd); 
//set the sortdirection 
cd.SortDirection = ListSortDirection.Descending; 
//handles the empty cells at the top 
cd.Comparer = new CustomSort(); 
 
#region CustomSort 
public class CustomSort : IComparer 
{ 
    public int Compare(object x, object y) 
    { 
        if (x == null && y == null) 
            return 0; 
        // Exclude empty values for comparison 
        else if (x == DBNull.Value) 
        { 
            return 0; 
        } 
        else if (y == DBNull.Value) 
        { 
            return 0; 
        } 
        else 
        { 
            return ((IComparable)x).CompareTo(y); 
        } 
    } 
} 
#endregion 
 
 
 

Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon