New: WPF DataGrid filtering

As requested by several customers, we have now added smart filtering options into our WPF DataGrid control. This is available right now in the current nightly build. Just like sorting and grouping, filtering is a must-have feature for users to easily sift through large amounts of data displayed in a DataGrid. It can be useful for displaying only the items of a particular state defined by an enum, or items that fall within a specified filtering range or even just used as a searching feature.

Filter row

Filter Row

There are currently two UI filtering options available. I’ll start with the simple option which is the filter row. Just like most of our DataGrid features, this can be enabled by simply setting a single property (IsFilterRowVisible) as shown below:

<ms:DataGrid IsFilterRowVisible="True">

The filter row is displayed just under the column header and automatically picks a simple filtering editor based on the data type displayed in the column. For string values, a text box can be used to search for strings that contain the user input string. Next to the text box is the option to match the casing. Enums, booleans, and objects that implement TypeConverter.GetStandardValues will use a combo box displaying all the standard values that the user can select from. The numeric filter appears as a single text box, but it will parse the user’s input allowing them to use symbols to define the filtering logic. Some of these symbols include: <, <=, >, >= and !. They can also use the hyphen symbol (-) between two numeric values to create a range filter. Multiple filtering expressions can be separated with a comma which allows the user to filter numeric columns exactly how they want.

Numeric Filter

Filter popup

The other option is to display a filter button in the column header which opens a popup for setting up more precise filtering expressions. Again this UI option can be enabled with a tiny bit of code:

<ms:DataGrid IsColumnHeaderFilterVisible="True">

For most data types, the popup displays an editor that allows the user to apply either a single filter, or two filters separated by AND/OR logic. The popup contains a combo box for the user to select a specific filter to use. For string values, they can select “Starts with”, “Ends with” or “Contains”.

String Filter

For comparable types, you get filters such as “Greater than”, “Less than or equal to”, “Not equal to” etc, and an appropriate editor is selected based on the type such as DropDownDateTimePicker, NumericTextBox, IntegerTextBox and so on.

Comparable Filters

And last of all is the filter for object types that provide a list of standard values. This is similar to the combo box displayed in the filter row, but this time allows for multiple selection.

Enum Filter

Programmatic filtering

All the classes used to build up filtering expressions are public, easy to use and composable. This allows you to build your own filtering expressions (possibly based on user interaction) and apply it to a column. All these classes can be found in the Mindscape.WpfElements.WpfDataGrid namespace and are named based on what they do e.g. StartsWithFilter, GreaterThanFilter, OrFilter and so on. You can also implement your own filters by implementing the IFilter interface which has the single IsMatch method. Once you’ve built up a custom filter expression, you can apply it by setting the Filter property on the appropriate DataGridColumn instance.

Want more?

This is only the first cut of the filtering feature. There are many ways we could extend this such as including a more diverse filter expression editor, add more built-in filters to save you time, support for more data types, a way to provide custom controls in the filter row or popup, a way to adjust UI filtering options per column and much more. If you are interested in particular filtering features for your application, let us know in the forum and we’ll prioritize based on your feedback.

Get DataGrid filtering now! If you have a trial version, you can grab the latest nightly build from here, or if you are already a customer, you can pick it up from your account page.

Tagged as WPF Elements

3 Responses to “New: WPF DataGrid filtering”


Join our mailer

You should join our newsletter! Sent monthly:

Back to Top