Skip to main content

ColumnView.FilterPopupExcelParseFilterCriteria Event

Allows you to parse the filter criteria applied to data and select the corresponding values in the filter menu.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Behavior")]
public event FilterPopupExcelParseFilterCriteriaEventHandler FilterPopupExcelParseFilterCriteria

Event Data

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

Property Description
Column Gets the processed grid column.
FilterCriteria Gets the applied filter criteria. Inherited from ParseFilterCriteriaEventArgs.
Path Gets the name of the processed data field or the full path to the data field through object relationships. Inherited from ParseFilterCriteriaEventArgs.
Value Gets an object that specifies the filter menu view model. Inherited from ParseFilterCriteriaEventArgs.
View Gets the view that raised the event.

The event data class exposes the following methods:

Method Description
SetBlanks() Selects the data value that corresponds to the blank value. Inherited from ParseFilterCriteriaEventArgs.
SetEmpty() Selects the data value that corresponds to the empty string value. Inherited from ParseFilterCriteriaEventArgs.
SetNotBlanks() Selects the data values that do not correspond to the blank value. Inherited from ParseFilterCriteriaEventArgs.
SetNotEmpty() Selects the data values that do not correspond to the empty string value. Inherited from ParseFilterCriteriaEventArgs.
SetNotNull() Selects the data values that do not correspond to the null value. Inherited from ParseFilterCriteriaEventArgs.
SetNull() Selects the data value that corresponds to the null value. Inherited from ParseFilterCriteriaEventArgs.
SetRange(Object, Object) Selects the specified range of values. Inherited from ParseFilterCriteriaEventArgs.
SetRange<T>(T, T) Selects the specified range of values. Inherited from ParseFilterCriteriaEventArgs.
SetResult(Object[], Boolean) For internal use. Inherited from ParseFilterCriteriaEventArgs.
SetValue(Object, Boolean) Selects the specified value. Inherited from ParseFilterCriteriaEventArgs.
SetValue<T>(T) Selects the specified value. Inherited from ParseFilterCriteriaEventArgs.
SetValues(Object[]) Selects the specified values. Inherited from ParseFilterCriteriaEventArgs.
SetValues<T>(IReadOnlyCollection<T>) Selects the specified values. Inherited from ParseFilterCriteriaEventArgs.
SetValuesOrBlanks(Object[]) Selects the specified values and the “Blanks” value. Inherited from ParseFilterCriteriaEventArgs.
SetValuesOrBlanks<T>(IReadOnlyCollection<T>) Selects the specified values and the “Blanks” value. Inherited from ParseFilterCriteriaEventArgs.

Remarks

The FilterPopupExcelQueryFilterCriteria event allows you to apply a custom filter criteria based on the values selected in a filter menu. This conversion is processed when the user selects a value in the menu/applies the selected values/closes the menu.

If you applied a custom filter criteria based on the selected data values, you should also handle the FilterPopupExcelParseFilterCriteria event to parse the filter criteria and select the corresponding values in the filter menu. This conversion is processed when the user opens the menu.

Example

A default column filter menu contains data values available in the column. The code below shows how to populate a filter menu with custom values.

image

Note

The example uses the grid control. The vertical grid, tree list, and pivot grid controls provide a similar API.

In this example, the processed column contains comma-separated values that can be treated as individual tokens. The FilterPopupExcelData event allows you to populate the menu with custom tokens instead of the available data values.

readonly static char[] separators = new char[] { ',', ' ' };

void OnFilterPopupExcelData(object sender, FilterPopupExcelDataEventArgs e) {
    // Create a collection of tokens based on data values.
    var tokens = new HashSet<string>();
    for(int i = 0; i < e.Values.Length; i++) {
        var parts = ((string)e.Values[i]).Split(separators, StringSplitOptions.RemoveEmptyEntries);
        for(int j = 0; j < parts.Length; j++)
            tokens.Add(parts[j]);
    }
    // Remove the default data values from the filter menu.
    e.ClearData();
    // Populate the menu with the created tokens.
    foreach(string t in tokens.OrderBy(x => x))
        e.AddData(t, t);
}

If you have populated the menu with custom tokens, you also must handle the following events:

  • FilterPopupExcelQueryFilterCriteria — to convert the selected tokens to the corresponding filter criteria that should be applied to data (direct conversion). This conversion is processed when the user selects a token in the menu/applies the selected tokens/closes the menu.

    void OnFilterPopupExcelQueryFilterCriteria(object sender, FilterPopupExcelQueryFilterCriteriaEventArgs e) {
        var viewModel = e.Value as ICollectionValueViewModel<string>;
        var property = new OperandProperty(e.Path);
        var functions = viewModel.Values
            .Select(x => new FunctionOperator(FunctionOperatorType.Contains, property, x));
        e.FilterCriteria = CriteriaOperator.Or(functions);
    }
    
  • FilterPopupExcelParseFilterCriteria — to convert the applied filter criteria to the corresponding tokens that should be selected in the menu (reverse conversion). This conversion is processed when the user opens the menu.

    void OnFilterPopupExcelParseFilterCriteria(object sender, FilterPopupExcelParseFilterCriteriaEventArgs e) {
        var func = e.FilterCriteria as FunctionOperator;
        if(!ReferenceEquals(func, null))
            e.SetValue(((OperandValue)func.Operands[1]).Value);
        var group = e.FilterCriteria as GroupOperator;
        if(!ReferenceEquals(group, null)) {
            var values = group.Operands
                .OfType<FunctionOperator>()
                .Select(x => ((OperandValue)x.Operands[1]).Value);
            e.SetValues(values.ToArray());
        }
    }
    
See Also