[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
  [Collapse]Expressions
    Expression Editor
    Custom Functions
    Custom Function Based Filters
    Member Table: Expressions
  [Expand]Behaviors
  [Expand]Application Appearance and Skin Colors
  [Expand]Filtering UI Context
   Find Panel Syntax
  [Expand]Graphics Performance and High DPI
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML-inspired Text Formatting
  [Expand]Menus
  [Expand]Tooltips
  [Expand]Save and Restore Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Custom Function Based Filters

Expanded Overview

You can display a filter based on a custom function in pop-up filter menus and filter editors. For example, the following image shows Black Friday Discount filter based on the corresponding custom function:

Note

Run the XtraGrid demo to try out the following custom function-based filters:

  • Is Black Friday Discount filter in the Discount column's pop-up filter menu and filter editor.
  • Is Weekend filter in the Sales Date column's pop-up filter menu and filter editor.
  • Not Begins With filter in the Name column's filter editor.

Custom Function Operands

Filters can be based on a custom function that accepts one (unary function) or two (binary function) operands:

  • the first operand - a field value being processed
  • the second operand - a value against which field values are evaluated (users specify the second operand in the filter editor)

The filter editor supports binary and unary functions; the pop-up filter menus support unary functions only.

Expanded How to Implement and Display a Custom Function Based Filter

To create a custom function that can be displayed as a filter, implement the ICustomFunctionDisplayAttributes interface. It extends the ICustomFunctionOperatorBrowsable interface with the following properties:

  • DisplayName — a string value that specifies the filter's caption.
  • Image — an System.Drawing.Image, SvgImage or image URI that specifies the filter's glyph.

Next, use the CriteriaOperator.RegisterCustomFunction or CriteriaOperator.RegisterCustomFunctions method to register the implemented function.

Do one of the following to display the corresponding filter in filter menus and the filter editor:

Unary Functions

Unary functions accept the single operand - the field value. Unary function-based filters do not allow users to specify a parameter.

The code below shows how to implement Black Friday Discount function. This is a unary function that evaluates to true if the operand is more than or equals 0.15.

Note

Run the XtraGrid demo and click Open Solution for the complete example.

Binary Functions

Binary functions accept the second operand - a user-specified parameter. Binary function-based filters can only be displayed in the filter editor.

The code below shows how to implement Not Begins With function. This is a binary function that evaluates to true if the first operand (the field value) not starts with the second operand (the value specified in the filter editor).

Note

Run the XtraGrid demo and click Open Solution for the complete example.

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