You can let users filter the visible rows in a WPF DataGrid by column and clear every active column filter from code in the current view.
Use column filters in a WPF DataGrid
A DataGrid is the table-style control used to present ViewModel list data as rows and columns. In WPF, the DataGrid provides column filters that the end user can apply from the column headers. A filter limits which rows are shown in that grid.
For example, a user can filter an Orders grid on its Status column to show only rows matching the value they enter or select through the grid's filter UI. The filter affects the current DataGrid display.
Use DataGrid filters when users need to narrow down an already displayed list. For general list behavior, including selection and actions, see Documentation:Tables and Grids.
Clear all active filters
Call ClearAllDataGridFilters() on IWECPOFService to remove all active column filters from the DataGrid in the current view.
- Get the
IWECPOFServicefrom the Eco service provider. - Call
ClearAllDataGridFilters()when your view needs to return the grid to its unfiltered state.
public void ClearAllDataGridFilters()
{
sp.GetEcoService<IWECPOFService>().ClearAllDataGridFilters();
}
For example, expose this code from a view command or action named Clear filters. When the user activates that action, all column filters applied in the current DataGrid are removed and the grid can again show the rows that its underlying list provides.
Choose the right filtering approach
DataGrid column filters are UI-level filtering for a displayed WPF grid. They are not a replacement for a search that selects data from persistent storage.
| Need | Use | Example |
|---|---|---|
| Let a user temporarily narrow the rows shown in a WPF DataGrid | DataGrid column filters | A user filters the visible Orders grid by Status. |
| Return a filtered grid to its normal display | IWECPOFService.ClearAllDataGridFilters()
|
A Clear filters action removes filters on Status, Customer, and Date columns. |
| Search or filter large persistent result sets | Seeker view criteria and OCL expressions | Search Persons whose last name starts with the entered text before presenting results. |
A Seeker view evaluates its criteria against persistent storage and is the appropriate design when the user must search a potentially large database result set. Do not rely on a displayed-grid filter when the requirement is to query all matching records in storage.
Platform notes
This page describes WPF DataGrid filters and the IWECPOFService clearing call. Grid filtering behavior is platform-specific.
- Documentation:Blazor documents the Blazor DataGrid implementation and its filtering mechanism.
- For WPF DataGrid appearance, including header and cell styles, see Documentation:Styling WPF Applications and ViewModels.
- If users must change values directly in grid rows, see Documentation:Edit in Grid.
