Experience Seamless Excel-Like Filtering in WinUI DataGrid 
Tags: csharp, dotnet, winui, desktop
Published: 2023-01-10 13:18:25

---
title: Experience Seamless Excel-Like Filtering in WinUI DataGrid 
published: true
date: 2023-01-10 11:30:00 UTC
tags: csharp, dotnet, winui, desktop
canonical_url: https://www.syncfusion.com/blogs/post/excel-like-filtering-in-winui-datagrid.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwjo8p6czrlpq5m731l2.png
---
Filtering is one of the most necessary features of any data grid. With it, users can find the data they require from a huge volume of data sets by applying criteria.

The [WinUI DataGrid](https://www.syncfusion.com/winui-controls/datagrid "Syncfusion WinUI DataGrid") control is used to display and manipulate tabular data efficiently. Its rich feature set includes data binding, editing, sorting, filtering, grouping, and data virtualization. It has been optimized to work with millions of records and handle high-frequency, real-time updates.

It also provides Excel-like filtering support to filter the rows more intuitively.

In this blog, we will see the various Excel-like filtering options available in the WinUI DataGrid.

## Getting started with Excel-like filtering

We can enable Excel-like filtering support for all columns by setting the [SfDataGrid.AllowFiltering](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_AllowFiltering "AllowFiltering property of WinUI DataGrid") property to **true**. The filter icon will be shown in the column headers.

Refer to the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/01/Enabling-Excel-Like-Filtering-in-WinUI-DataGrid-1.png" alt="Enabling Excel-Like Filtering in WinUI DataGrid" style="width:100%">

  <figcaption>Enabling Excel-Like Filtering in WinUI DataGrid</figcaption>

</figure>
By clicking on the filter icon, you can see the Excel-like pop-up menu, as shown in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/01/WinUI-DataGrid-with-Excel-Like-Filtering-Pop-Up-1.png" alt="WinUI DataGrid with Excel-Like Filtering Pop-Up" style="width:100%">

  <figcaption>WinUI DataGrid with Excel-Like Filtering Pop-Up</figcaption>

</figure>

## Features of Excel-like filtering in WinUI DataGrid

The Excel-like filtering support in our WinUI DataGrid has almost all the options available in the Microsoft Excel filtering menu:

- Sorting: Easily sort the rows in ascending or descending order.
- Clear filter: Clear the current filter applied to the column.
- Advanced filtering.
- Checkbox filtering.

Let’s look at the latter two options in more detail.

### Advanced filtering

With advanced filtering, users can filter for the required data by applying multiple filter conditions with filter criteria. Each type of filter has its own set of filter conditions to apply filtering with ease.

The advanced filtering options are available based on the data type of the columns.

Supported data types:

- Text
- Number
- Date

The following table shows the list of filter conditions supported in advanced filter options.
<table style="width: 81.9797%; height: 625px;">
<tbody>
<tr style="background: none;">
<td style="width: 31.6009%; height: 68px;">
<p><strong>Text</strong></p>
</td>
<td style="width: 25.6924%; height: 68px;">
<p><strong>Number</strong></p>
</td>
<td style="width: 20.5071%; height: 68px;">
<p><strong>Date</strong></p>
</td>
</tr>
<tr style="height: 583px;">
<td style="width: 31.6009%; height: 557px;">
<p>· Equals</p>
<p>· Does Not Equal</p>
<p>· Begins With</p>
<p>· Does Not Begin With</p>
<p>· Ends With</p>
<p>· Does Not End With</p>
<p>· Contains</p>
<p>· Does Not Contain</p>
<p>· Empty</p>
<p>· Not Empty</p>
<p>· Null</p>
<p>· Not Null</p>
</td>
<td style="width: 25.6924%; height: 557px;">
<p>· Equals</p>
<p>· Does Not Equal</p>
<p>· Null</p>
<p>· Not Null</p>
<p>· Less Than</p>
<p>· Less Than or Equal</p>
<p>· Greater Than</p>
<p>· Greater Than or Equal</p>
</td>
<td style="width: 20.5071%; height: 557px;">
<p>· Equals</p>
<p>· Does Not Equal</p>
<p>· Before</p>
<p>· Before Or Equal</p>
<p>· After</p>
<p>· After or Equal</p>
<p>· Null</p>
<p>· Not Null</p>
</td>
</tr>
</tbody>
</table>

You can also choose whether the **AND** or **OR** logical operator should be applied between the two filter conditions you apply in the advanced filter.

Refer to the following GIF image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/01/Advanced-Filtering-Support-in-WinUI-DataGrid-1.gif" alt="Advanced Filtering Support in WinUI DataGrid" style="width:100%">

  <figcaption>Advanced Filtering Support in WinUI DataGrid</figcaption>

</figure>

### Checkbox filtering

Checkboxes are the most common filtering option used to filter rows. By using a checked ListBox in the filter pop-up, you can easily select the data you want to view.  A blank item is added automatically if the column has null or empty data.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/01/Checkbox-Filtering-Support-in-WinUI-DataGrid-1.gif" alt="Checkbox Filtering Support in WinUI DataGrid" style="width:100%">

  <figcaption>Checkbox Filtering Support in WinUI DataGrid</figcaption>

</figure>

### Events

The following events will be called when we apply filtering through the Excel-like filter pop-up:

- [FilterChanging](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_FilterChanging "FilterChanging event of WinUI DataGrid"): This is invoked while applying filtering to a specific column.
- [FilterChanged](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_FilterChanged "FilterChanged event of WinUI DataGrid"): This is invoked after the filtering is applied to a specific column.
- [FilterItemsPopulating](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_FilterItemsPopulating "FilterItemsPopulating event of WinUI DataGrid"): This is invoked while populating a list of items in the checked list box.
- [FilterItemsPopulated](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_FilterItemsPopulated "FilterItemsPopulated event of WinUI DataGrid"): This is invoked after the list of items in the checked list boxes is populated.

## Programmatic filtering

Along with the Excel-like filtering UI, you can also filter data programmatically through:

- View filtering
- Column filtering

### View filtering

This feature enables users to apply logic to an entire row. This approach requires a bool return type method with an underlying data object as the parameter. This user-defined method will be called for every row in the DataGrid, and the user can return **true** or **false** based on the logic. If the return value is **true** , then that row will be filtered. Other rows will not be displayed in the view.

View filtering can be achieved by setting the [SfDataGrid.View.Filter](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.Data.ICollectionViewAdv.html#Syncfusion_UI_Xaml_Data_ICollectionViewAdv_Filter "View.Filter property of WinUI DataGrid") delegate. You can refresh the view by calling the [SfDataGrid.View.RefreshFilter](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.Data.ICollectionViewAdv.html#Syncfusion_UI_Xaml_Data_ICollectionViewAdv_RefreshFilter_System_Boolean_ "View.RefreshFilter method of WinUI DataGrid")method.

Refer to the following code example.

```csharp
public bool FilterRecords(object data)
{
    string filterText = "Germany";
    var item = data as OrderInfo;

    if (item != null)
    {
        if (item.Country.Equals(filterText))
            return true;
    }
    return false;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    if (sfDataGrid != null && sfDataGrid.View != null)
    {
    	sfDataGrid.View.Filter = FilterRecords;
    	sfDataGrid.View.RefreshFilter();
    }
}

```

Refer to the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/01/View-Filtering-in-WinUI-DataGrid-1.png" alt="View Filtering in WinUI DataGrid" style="width:100%">

  <figcaption>View Filtering in WinUI DataGrid</figcaption>

</figure>

### Column filtering

This approach enables users to apply the filter conditions based on specific columns. So, rows will be filtered based on the specific column criteria.

Column filtering can be done using the [GridColumn.FilterPredicates](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.GridColumn.html#Syncfusion_UI_Xaml_DataGrid_GridColumn_FilterPredicates "GridColumn.FilterPredicates property of WinUI DataGrid") property by adding the [FilterPredicate](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.Data.FilterPredicate.html "FilterPredicate Class of WinUI DataGrid") to it. You can specify your required criteria in the filter predicate.

In the following example, we will use the **OrderID** column to filter the data, which has a **1005** value.

```csharp
sfDataGrid.Columns["OrderID"].FilterPredicates.Add(new FilterPredicate() { FilterType = FilterType.Equals, FilterValue = "1005" });
```

Refer to the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/01/Programmatic-Column-Filtering-in-WinUI-DataGrid-1.png" alt="Programmatic Column Filtering in WinUI DataGrid" style="width:100%">

  <figcaption>Programmatic Column Filtering in WinUI DataGrid</figcaption>

</figure>

## References

For more details, refer to the [Excel-like filtering in the WinUI DataGrid GitHub demo](https://github.com/syncfusion/winui-demos/blob/master/datagrid/Views/AdvanceFilter.xaml "Excel-Like Filtering in WinUI DataGrid GitHub demos") and [documentation](https://help.syncfusion.com/winui/datagrid/filtering "Getting Started with Filtering in WinUI DataGrid").

## Conclusion

Thanks for reading! I hope you enjoyed this blog about Excel-like filtering in Syncfusion’s [WinUI DataGrid](https://www.syncfusion.com/winui-controls/datagrid "Syncfusion WinUI DataGrid") control. Try out this user-friendly feature and experience seamless filtering!

For current Syncfusion customers, the newest version of Essential Studio is available from the [license and downloads page](https://www.syncfusion.com/account/downloads "License and downloads page of Essential Studio"). If you are not yet a customer, you can try our [30-day free trial](https://www.syncfusion.com/downloads "Free evaluation of the Syncfusion Essential Studio") to check out these new features.

If you have questions, contact us through our [support forums](https://www.syncfusion.com/forums "Syncfusion Support Forum"), [feedback portal](https://www.syncfusion.com/feedback "Syncfusion Feedback Portal"), or [support portal](https://support.syncfusion.com/ "Syncfusion Support Portal"). We are always happy to assist you!

## Related blogs

- [Top 10 Features of WinUI 3 DataGrid Control for Efficient Data Handling](https://www.syncfusion.com/blogs/post/top-10-features-of-winui-3-datagrid-control-for-efficient-data-handling.aspx "Blog: Top 10 Features of WinUI 3 DataGrid Control for Efficient Data Handling")
- [Easily Design a Sleep Tracker Using WinUI Radial Gauge](https://www.syncfusion.com/blogs/post/design-a-sleep-tracker-using-winui-radial-gauge.aspx "Blog: Easily Design a Sleep Tracker Using WinUI Radial Gauge")
- [Advantages of Using Syncfusion WinUI Controls over Framework Controls: Part 1](https://www.syncfusion.com/blogs/post/advantages-of-using-syncfusion-winui-controls-over-framework-controls-part-1.aspx "Blog: Advantages of Using Syncfusion WinUI Controls over Framework Controls: Part 1")
- [Advantages of Using Syncfusion WinUI Controls over Framework Controls: Part 2](https://www.syncfusion.com/blogs/post/advantages-of-using-syncfusion-winui-controls-over-framework-controls-part-2.aspx "Blog: Advantages of Using Syncfusion WinUI Controls over Framework Controls: Part 2")