Skip to main content
A newer version of this page is available. .

FilterEditorControl.QueryOperators Event

Allows you to customize the operator list.

Namespace: DevExpress.Xpf.Core.FilteringUI

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

Declaration

public event EventHandler<FilterEditorQueryOperatorsEventArgs> QueryOperators

Event Data

The QueryOperators event's data class is FilterEditorQueryOperatorsEventArgs. 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>.
Filter Gets the current filter criteria specified in the FilterEditorControl.
Operators Gets or sets the operators displayed in the operator list.

Remarks

Tip

Demo: Filter Editor - Customize the Operator List

Requires installation of WPF Subscription. Download

The Filter Editor 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:TableView x:Name="view">
    <dxg:TableView.FilterEditorTemplate>
        <DataTemplate>
            <dxfui:FilterEditorControl QueryOperators="OnQueryOperators" />
        </DataTemplate>
    </dxg:TableView.FilterEditorTemplate>
</dxg:TableView> 
void OnQueryOperators(object sender, FilterEditorQueryOperatorsEventArgs e) {
    if(e.FieldName == "OrderDate") {
        e.Operators.Clear();
        e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Equal));
        e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.NotEqual));
    }
} 

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.v19.1.Extensions.dll library. Refer to c:\Program Files (x86)\DevExpress 19.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.

    CriteriaOperator.RegisterCustomFunction(customFunction);
    
  3. Create the FilterEditorOperatorItem and add it to the FilterEditorQueryOperatorsEventArgs.Operators collection. Specify the operator item’s edit settings to define its operands:

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the QueryOperators event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also