FilterOperators - STARIONGROUP/COMET-IME-Community-Edition GitHub Wiki

Introduction

In browsers that contain a GridControl or a TreeListControl, we use our own custom Filter Editor Dialog. This allows us to implement extra logic for custom filtering for specific data. An example is the implementation of the IsMemberOfCategory and HasAppliedCategory filter operators which are custom made for Category data.

XAML

The system starts in the CommonThingControl control in XAML, which should be present in the view/browser. Under the hood things are setup in the CommonThingControl, for the Custom Filter Dialog to work as expected. If a column in a GridControl or TreeListControl needs a special custom filter, then that can be done by adding a behaviour to the column definition:

<dxg:TreeListColumn FieldName="Category" Header="Category" Visible ="False" ShowInColumnChooser="False">
   <dxmvvm:Interaction.Behaviors>
      <behaviors:FilterOperatorBehavior CustomFilterOperatorType="Category" ItemsSource="{Binding ElementDefinitionRowViewModels}"/>
   </dxmvvm:Interaction.Behaviors>
</dxg:TreeListColumn>
<dxg:TreeListColumn FieldName="ParameterTypeName" Header="ParameterTypeName" Visible ="False" ShowInColumnChooser="False" />

In the example, the Category TreeListColumn has the FilterOperatorBehaviour applied. The CustomFilterOperatorType is of type "Category" (explained later in this document) and provides the DataContext's ElementDefinitionRowViewModels property as a datasource used to find the values for the filter's dropdown/autocomplete list to be used in the Custom Filter Dialog. The second row just adds an extra column, that is not visible and not choosable in the TeeListControl's column chooser. It does however show in the Custom Filter Dialog, because every column is automatically allowed to do that.

Create a FilterOperatorHandler

In the XAML example the CustomFilterOperatorType was mentioned. That is the heart of the business logic for the custom filter operator. In COMETComposition there are 3 classes that are important when you create a custom filter operator:

CustomFilterOperatorType

This is an enum, that contains all available custom filter editor types. The FilterOperatorBehavior.CustomFilterOperatorType property is of type CustomFilterOperatorType, so that's the way to link a specific column in XAML to a custom filter editor.

CustomFilterOperatorHandler

The CustomFilterOperatorHandler is an abstract base class for all custom filter editor handlers. A ??????FilterOperatorHandler class that inherits this from class should be used to create the business logic for your new custom filter editor.

CustomFilterOperatorHandlerFactory

The CustomFilterOperatorHandlerFactory is the final component that connects dots from XAML to business logic. This static class is used to create ??????FilterOperatorHandler.

Implementing

So, you add the name of your custom filter editor handler in CustomFilterOperatorType. Then you create the ??????FilterOperatorHandler class where you add/remove operators, register custom functions to the DevExpress FilterCriteria options and define the business logic for filling the dropdown/autocomplete in the filter UI. Examples can be found in the CategoryFilterOperatorHandler class. The last step is add code to the CustomFilterOperatorHandlerFactory.CreateFilterOperatorHandler method, so an instance of your ??????FilterOperatorHandler can be instanciated according to the CustomFilterOperatorType.

In CreateFilterOperatorHandler add code where you instanciate the ??????FilterOperatorHandler class for the specific CustomFilterOperatorType.