<syncfusion:GridTextColumn MappingName="FirstName" SortMode="Display" /> |
<syncfusion:SfDataGrid Name="dataGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding Employees}"
AllowFiltering="True"
FilterItemsPopulated="DataGrid_FilterItemsPopulated">
private void DataGrid_FilterItemsPopulated(object sender, Syncfusion.UI.Xaml.Grid.GridFilterItemsPopulatedEventArgs e)
{
(e.ItemsSource as List<FilterElement>).Sort(new FilterElementComparer());
}
public class FilterElementComparer : IComparer<FilterElement>
{
public int Compare(FilterElement x, FilterElement y)
{
if (x == null)
{
if (y == null)
{
// If x is null and y is null, they're
// equal.
return 0;
}
else
{
// If x is null and y is not null, y
// is greater.
return -1;
}
}
else
{
// If x is not null...
//
if (y == null)
// ...and y is null, x is greater.
{
return 1;
}
else
{
return x.DisplayText.CompareTo(y.DisplayText);
}
}
}
} |