|
this.sfDataGrid.SortComparers.Add(new Syncfusion.Data.SortComparer() { Comparer = new CustomComparer(), PropertyName = "Country" });
public class CustomComparer : IComparer<object>, ISortDirection {
public int Compare(object x, object y)
{
string nameX;
string nameY;
//While data object passed to comparer
if (x.GetType() == typeof(OrderInfo))
{
nameX = ((OrderInfo)x).Country;
nameY = ((OrderInfo)y).Country;
if (nameX.CompareTo(nameY) > 0)
return SortDirection == ListSortDirection.Ascending ? 1 : -1;
else if (nameX.CompareTo(nameY) == -1)
return SortDirection == ListSortDirection.Ascending ? -1 : 1;
else
return 0;
}
//While sorting groups
else if (x.GetType() == typeof(Group))
{
int countX;
int countY;
//Calculating the group key length
countX = ((Group)x).Source.Count;
countY = ((Group)y).Source.Count;
if (countX.CompareTo(countY) > 0)
return SortDirection == ListSortDirection.Ascending ? 1 : -1;
else if (countX.CompareTo(countY) == -1)
return SortDirection == ListSortDirection.Ascending ? -1 : 1;
else
return 0;
}
return 0;
}
private ListSortDirection _SortDirection;
/// <summary>
/// Gets or sets the property that denotes the sort direction.
/// </summary>
/// <remarks>
/// SortDirection gets updated only when sorting the groups. For other cases, SortDirection is always ascending.
/// </remarks>
public ListSortDirection SortDirection
{
get { return _SortDirection; }
set { _SortDirection = value; }
}
} |
this.sfDataGrid.SortComparers.Add(new Syncfusion.Data.SortComparer() { Comparer = new CustomComparer(), PropertyName = "Country" });