Skip to main content
All docs
V24.2

TreeListDataColumnFilterRowCellTemplateContext.FilterCriteria Property

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

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.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 TreeList 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 TreeList column:

Filter Row Template

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

<DxTreeList @ref="TreeList" Data="TreeListData" ChildrenFieldName="Satellites" ShowFilterRow="true">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" Width="30%">
            <FilterRowCellTemplate>
                <DxTagBox TData="string"
                          TValue="string"
                          Data="Types"
                          Values="GetTagBoxValues(context)"
                          ValuesChanged="newValues => UpdateCriteria(newValues, context)" />
            </FilterRowCellTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2">
            <HeaderCaptionTemplate>Mass, 10<sup>21</sup> &#215; kg</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" />
        <DxTreeListDataColumn FieldName="Volume10pow9KM3" DisplayFormat="N2">
            <HeaderCaptionTemplate>Volume, 10<sup>9</sup> &#215; km<sup>3</sup></HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="SurfaceGravity" DisplayFormat="N2">
            <HeaderCaptionTemplate>Gravity, m/s<sup>2</sup></HeaderCaptionTemplate>
        </DxTreeListDataColumn>
    </Columns>
</DxTreeList>

@code {
    object TreeListData { get; set; }
    IEnumerable<string> Types = new List<string> { 
        "Star", "Planet", "Satellite", "Dwarf planet", "Asteroid" };
    ITreeList TreeList { get; set; }

    protected override async Task OnInitializedAsync() {
        TreeListData = SpaceObjectDataProvider.GenerateData();
    }
    IEnumerable<string> GetTagBoxValues(TreeListDataColumnFilterRowCellTemplateContext 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,TreeListDataColumnFilterRowCellTemplateContext 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 TreeList layout, the TreeList component determines the filter criteria applied to each column based on the TreeListPersistentLayout.FilterCriteria property value. The component cannot determine a column’s criteria operator if it includes complex operands (AggregateOperand or JoinOperand). In this case, the TreeList excludes complex operands from the column’s criteria operator, and the FilterCriteria property value may differ from the 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