ExcelStyleFilterElement.QueryOperators Event

Allows you to customize operators in the Excel-style Filter Element.

Namespace: DevExpress.Xpf.Core.FilteringUI

Assembly: DevExpress.Xpf.Grid.v21.1.dll


public event EventHandler<ExcelStyleFilterElementQueryOperatorsEventArgs> QueryOperators

Event Data

The QueryOperators event's data class is ExcelStyleFilterElementQueryOperatorsEventArgs. The following properties provide information specific to this event:

Property Description
DefaultOperator Gets or sets an operator that is selected when users create a new filter condition. Inherited from QueryOperatorsEventArgsBase<T>.
FieldName Gets a name of the field for which operators are queried. Inherited from QueryOperatorsEventArgsBase<T>.
Operators Gets or sets operators displayed in the operator list.


Run Demo: Excel-style Drop-down Filter - Customize the Operator List

The Excel-style Filter Element shows a list of operators the selected field accepts. Use the QueryOperators event to customize the operator list.

The code sample below removes all operators except Equal and Not Equal:

<dxg:GridColumn FieldName="OrderDate">
            <dxfui:ExcelStyleFilterElement x:Name="PART_FilterElement" QueryOperators="OnExcelStyleFilterQueryOperators"/>
void OnExcelStyleFilterQueryOperators(object sender, ExcelStyleFilterElementQueryOperatorsEventArgs e) {
    if(e.FieldName == "OrderDate") {
        e.Operators.Add(new ExcelStyleFilterElementOperatorItem(ExcelStyleFilterElementOperatorType.Equal) { Caption = "Equal" });
        e.Operators.Add(new ExcelStyleFilterElementOperatorItem(ExcelStyleFilterElementOperatorType.NotEqual) { Caption = "Not Equal" });

Custom Operators

You can use the QueryOperators event to add custom operators. The code sample below adds the Last Years operator:

  1. Create a custom function. Do one of the following:

    • Use the CustomFunctionFactory.Create method.

      The CustomFunctionFactory is an extension of the DevExpress.Xpf.Grid.v21.1.Extensions.dll library. Refer to c:\Program Files (x86)\DevExpress 21.1\Components\Sources\DevExpress.Xpf.Grid\DevExpress.Xpf.Grid.Extensions\ for information on how extension methods work.

      The CustomFunctionFactory.Create method allows you to create a custom function with a maximum of 4 operands.

    • Implement the ICustomFunctionOperator interface. Refer to the Implementing Custom Functions topic for more information.

    const string CustomFunctionName = "LastYears";
    var currentYear = DateTime.Now.Year;
    ICustomFunctionOperatorBrowsable customFunction = CustomFunctionFactory.Create(CustomFunctionName, 
        (DateTime date, int threshold) => {
            return currentYear >= date.Year && currentYear - date.Year <= threshold;
  2. Call the CriteriaOperator.RegisterCustomFunction method to register the custom function.

  3. Create the ExcelStyleFilterElementOperatorItem and add it to the ExcelStyleFilterElementQueryOperatorsEventArgs.Operators collection. Specify the operator item’s edit settings to define its operands:

    void OnExcelStyleFilterQueryOperators(object sender, ExcelStyleFilterElementQueryOperatorsEventArgs e) {
        if(e.FieldName == "OrderDate") {
            // ...
            var customFunctionEditSettings = new BaseEditSettings[] { 
                new TextEditSettings { MaskType = MaskType.Numeric, Mask = "D", MaskUseAsDisplayFormat = true } 
            e.Operators.Add(new ExcelStyleFilterElementOperatorItem(CustomFunctionName, customFunctionEditSettings) { Caption = "Last Years" });
See Also