[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Expand]Controls and Libraries
 [Collapse]Scaffolding Wizard
   Getting Started
  [Expand]Data Access Layer
   UI Generation
    How to: Affect Auto-Generated Columns and Edit Fields at the Data Model Level
    How to: Create a Custom Filter
    How to: Add a New Detail Collection
    How to: Show Validation Errors when IDataErrorInfo is Used
    How to: Show Detail Views in Separate Windows
    How to: Manage Document Properties and Open Them Manually
    How to: Implement Many-to-many Relationships Editing
    Entity Names Autogeneration
    How to: Use Projections to Create Custom Queries and Optimize Performance
    How To: Improve Performance by Using the Instant Feedback Mode
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Create a Custom Filter

This document describes how to add a filter to the data used in your application created with the Scaffolding Wizard. This wizard helps you quickly generate an application with the required filtering functionality.

A CollectionViewModel class generated by the Scaffolding Wizard provides the FilterExpression property, which allows you to filter data. Set this property to the required expression.

In this example, the database contains messages of different types: questions, bug reports and suggestions. Your task is as follows:

  • For developers, hide questions and only show bug reports and suggestions;
  • For support engineers, only show questions.

In this case, it is useful to only load items of the required type. To do this, create a set of filters in your View Model.

Then, populate an editor with these filters and bind its value to FilterExpression.

In this case, items will automatically be filtered as soon as the user changes the editor's value.

Here is a screenshot of the updated application.

In order to save the selected filter across application restarts, the IssuesCollectionViewModel implements the ISupportLogicalLayout<string> interface.

Since the CollectionViewModel class implements the non-parameterized base interface ISupportLogicalLayout, only RestoreState and SaveState methods need to be implemented.


A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T111346.

You can also learn how to Add advanced end-user filtering functionality to applications.

Is this topic helpful?​​​​​​​