Skip to main content

GridDataColumnFilterRowCellTemplateContext.FilterCriteria Property

Specifies the filter criteria the filter row applies to the data column.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public CriteriaOperator FilterCriteria { get; set; }

Property Value

Type Description
CriteriaOperator

The filter criteria.

Remarks

When the ShowFilterRow is set to true, the grid displays the filter row. The FilterRowCellTemplate property allows you to display a custom editor in the filter row cell. The template’s context parameter contains the FilterCriteria property that specifies the filter criteria applied to the column.

The following code snippet uses the FilterCriteria property to implement a tag box filter for a grid column.

@using DevExpress.Data.Filtering
@using DevExpress.Data.Filtering.Helpers
@inject NwindDataService NwindDataService

<DxGrid @ref="Grid" Data="GridData" ShowFilterRow="true">
    <Columns>
        <DxGridDataColumn FieldName="OrderID"/>
        <DxGridDataColumn FieldName="ShipCountry">
            <FilterRowCellTemplate>
                <DxTagBox TData="string"
                          TValue="string"
                          Data="Countries"
                          Values="GetTagBoxValues(context)"
                          ValuesChanged="newValues => UpdateCriteria(newValues, context)"/>
            </FilterRowCellTemplate>
        </DxGridDataColumn>
        <DxGridDataColumn FieldName="OrderDate"/>
        <DxGridDataColumn FieldName="ShipVia"/>
    </Columns>
</DxGrid>

@code {

    object GridData { get; set; }
    IEnumerable<string> Countries { get; set; }
    IGrid Grid { get; set; }

    protected void SetData() {
        GridData = DbContext.Orders.ToList();
        Countries = DbContext.Orders.Select(x => x.ShipCountry).Distinct().ToArray();
    }

    IEnumerable<string> GetTagBoxValues(GridDataColumnFilterRowCellTemplateContext context) {
        if(context.FilterCriteria.ReferenceEqualsNull())
            return null;
        if(!context.FilterCriteria.Is<InOperator>(out var inOperator))
            return null;
        if(!inOperator.LeftOperand.Is<OperandProperty>(out var leftOperand))
            return null;
        if(leftOperand.PropertyName != context.DataColumn.FieldName)
            return null;

        var result = new List<string>();
        foreach(var operand in inOperator.Operands) {
            if(!operand.Is<OperandValue>(out var operandValue))
                return null;
            result.Add((string)operandValue.Value);
        }
        return result;
    }
    void UpdateCriteria(IEnumerable<string> newValues, GridDataColumnFilterRowCellTemplateContext context) {
        if(!newValues.Any()) {
            context.FilterCriteria = null;
            return;
        }
        context.FilterCriteria = new InOperator(
            new OperandProperty(context.DataColumn.FieldName),
            newValues.Select(value => new OperandValue(value))
        );
    }
}

Limitations

When you restore a grid’s layout, the Grid component determines the filter criteria applied to each column based on the GridPersistentLayout.FilterCriteria property value. The component cannot determine a column’s criteria operator if it includes complex operands (AggregateOperand or JoinOperand). In this case, the Grid excludes complex operands from the column’s criteria operator, and the FilterCriteria property value may differ from the actual filter applied to the column.

GridDevExtremeDataSource Specifics

The GridDevExtremeDataSource is based on the DevExtreme.AspNet.Data library that uses its own filter language syntax. Some structures of criteria language syntax cannot be converted to DevExtreme data source syntax. This section describes criteria operators that are supported by the GridDevExtremeDataSource.

Binary Operator

The BinaryOperator criteria operator allows you to compare operand property with operand value. You can use the following operator types for comparison: Equal, NotEqual, Greater, GreaterOrEqual, Less, and LessOrEqual.

var criteria = new BinaryOperator("UnitPrice", 20, BinaryOperatorType.Less);

Unary Operator

The UnaryOperator criteria operator allows you to apply Not or IsNull operation to an expression.

var criteria = new UnaryOperator(UnaryOperatorType.Not, new UnaryOperator(UnaryOperatorType.IsNull, "Region"));

Function Operator

The FunctionOperator criteria operator allows you to create a complex filter criteria with the following operator types:

  • IsNull and IsNullOrEmpty operands indicate whether a specified operand is a null reference or an empty string.
  • InRange operand determines whether a property value is contained in the specified range.
  • StartsWith, EndsWith, and Contains operands allow you to compare a property with a string value.
var criteria = new FunctionOperator(FunctionOperatorType.StartsWith, new OperandProperty("ShipCountry"), "it");

Group Operator

The GroupOperator criteria operator allows you to create a logical expression that groups two or more operands with a logical AND or OR.

var criteria = new GroupOperator(GroupOperatorType.And,
        new BinaryOperator("UnitPrice", 20, BinaryOperatorType.Less),
        new FunctionOperator(FunctionOperatorType.StartsWith, new OperandProperty("ShipCountry"), "it"));

Between Operator

The BetweenOperator criteria operator allows you to determine whether a criteria expression lies between the specified range of values.

var criteria = new BetweenOperator("UnitPrice", 15, 20);

In Operator

The InOperator criteria operator allows you to determine whether a property value matches any value in a specified list.

var criteria = new InOperator("ShipCountry", new string[] { "Italy", "German", "France" });
See Also