Hi Deniss,
Thank for contacting Syncfusion Support.
Query 1 [Sort Comparer object contains the instance of class]
In SortComparer we have passed the whole instance of the corresponding class which is the behavior of SfDataGrid SortComparer. Because we have provided the support for comparing the all properties of that particular instance.
Query 2 [ One SortComparer for many Columns ]
In SfDataGrid you can able to handle sorting for different Columns using common SortComparer. We have prepared the sample as per your requirement and you can download the same from the below location,
Sample : http://www.syncfusion.com/downloads/support/forum/122128/ze/SortingDemo-1024702161
Please refer the below link to know more about the SortComparer in SfDataGrid,
Link : http://help.syncfusion.com/wpf/sfdatagrid/sorting#custom-sorting
Regards,
Sowndaiyan
Hi Deniss,
Thank for contacting Syncfusion Support.
Query 1 [Sort Comparer object contains the instance of class]
In SortComparer we have passed the whole instance of the corresponding class which is the behavior of SfDataGrid SortComparer. Because we have provided the support for comparing the all properties of that particular instance.
Query 2 [ One SortComparer for many Columns ]
In SfDataGrid you can able to handle sorting for different Columns using common SortComparer. We have prepared the sample as per your requirement and you can download the same from the below location,
Sample : http://www.syncfusion.com/downloads/support/forum/122128/ze/SortingDemo-1024702161
Please refer the below link to know more about the SortComparer in SfDataGrid,
Link : http://help.syncfusion.com/wpf/sfdatagrid/sorting#custom-sorting
Regards,
Sowndaiyan
<syncfusion:SfDataGrid.SortComparers>
<Linq:SortComparer PropertyName="OrderDate" >
<Linq:SortComparer.Comparer>
<local:CustomerInfo SortString="OrderDate"/>
</Linq:SortComparer.Comparer>
</Linq:SortComparer>
<Linq:SortComparer PropertyName="CustomerID">
<Linq:SortComparer.Comparer>
<local:CustomerInfo SortString="CustomerID"/>
</Linq:SortComparer.Comparer>
</Linq:SortComparer>
</syncfusion:SfDataGrid.SortComparers>
public class CustomerInfo : IComparer<Object>, ISortDirection
{
private string _sortstring;
public string SortString
{
get
{
return _sortstring;
}
set
{
_sortstring = value;
}
}
public int Compare(object x, object y)
{
int namX;
int namY;
//For Customers Type data
if (x.GetType() == typeof(Orders))
{
if (SortString == "OrderDate")
{
//Calculating the Date of OrderDate if the object type is Orders
//sorting can be performed based upon the "day"
DateTime date1 = ((Orders)x).OrderDate.Value;
DateTime date2 = ((Orders)y).OrderDate.Value;
namX = date1.Day;
namY = date2.Day;
}
else
{
namX = ((Orders)x).CustomerID.ToString().Length;
namY = ((Orders)y).CustomerID.ToString().Length;
}
}
//For Group type Data
else if (x.GetType() == typeof(Group))
{
//Calculating the group key length
namX = ((Group)x).Key.ToString().Length;
namY = ((Group)y).Key.ToString().Length;
}
else
{
namX = x.ToString().Length;
namY = y.ToString().Length;
}
// Objects are compared and return the SortDirection
if (namX.CompareTo(namY) > 0)
return SortDirection == ListSortDirection.Ascending ? 1 : -1;
else if (namX.CompareTo(namY) == -1)
return SortDirection == ListSortDirection.Ascending ? -1 : 1;
else
return 0;
}
//Get or Set the SortDirection value
private ListSortDirection _SortDirection;
public ListSortDirection SortDirection
{
get { return _SortDirection; }
set { _SortDirection = value; }
}
} |