Articles in this section

How to sort checkbox items in the FilterPopup based on the DisplayValue?

By default, in WPF DataGrid(SfDataGrid) GridComboBoxColumn the checkbox elements in the FilterPopup will be sorted based on the edit value (SelectedValuePath) of the column. You can sort the checkbox elements in the FilterPopup based on the display value (DisplayMemberPath) of the column by using a custom sort comparer for the filter elements in the SfDataGrid.FilterItemsPopulated event.

 

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);
            }
        }
    }
}

 

Custom sort for FilterElement

 

Take a moment to peruse the documentation, where you can find about sorting, with code examples.

Please refer this link to know about the essential features of Syncfusion WPF DataGrid.

You can download the example from GitHub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied