Skip to main content
All docs
V24.2

DxTreeList.SetFilterCriteria(CriteriaOperator) Method

Applies a filter to TreeList data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public void SetFilterCriteria(
    CriteriaOperator criteria
)

Parameters

Name Type Description
criteria CriteriaOperator

The filter expression.

Remarks

Call the SetFilterCriteria method to filter TreeList data in code.

To apply a filter, create a criteria operator object that specifies the filter expression and pass this object to the SetFilterCriteria method. When you call this method, the TreeList clears any applied filters. You can filter TreeList data by every data source field, including the fields not displayed in the TreeList.

When a filter is applied, the TreeList raises the FilterCriteriaChanged event.

@inject SpaceObjectDataProvider SpaceObjectDataProvider

<DxTreeList @ref="TreeList" Data="Data" ChildrenFieldName="Satellites">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" />
        <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" />
        <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">
            <HeaderCaptionTemplate>Radius, km</HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="Volume10pow9KM3" DisplayFormat="N2">
            <HeaderCaptionTemplate>Volume, 10<sup>9</sup> &#215; km<sup>3</sup></HeaderCaptionTemplate>
        </DxTreeListDataColumn>
        <DxTreeListDataColumn FieldName="SurfaceGravity" Caption="Gravity" DisplayFormat="N2">
            <HeaderCaptionTemplate>Gravity, m/s<sup>2</sup></HeaderCaptionTemplate>
        </DxTreeListDataColumn>
    </Columns>
    <ToolbarTemplate>
        <div class="cw-480">
            <DxTagBox Data="SpaceObjectTypes"
                      CssClass="cw-480 option-component"
                      Values="SelectedSpaceObjectTypes"
                      ValuesChanged="(IEnumerable<string> values) => TagBox_ValuesChanged(values)"
                      NullText="Select object type..."
                      ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
                      aria-label="Select object type" />
        </div>
    </ToolbarTemplate>
</DxTreeList>

@code {
    ITreeList TreeList { get; set; }
    object Data { get; set; }
    IEnumerable<string> SpaceObjectTypes { get; } = new[] {
        "Star", "Planet", "Dwarf planet", "Satellite", "Asteroid"
    };
    IEnumerable<string> SelectedSpaceObjectTypes { get; set; }
    protected override void OnInitialized() {
        Data = SpaceObjectDataProvider.GenerateData();
    }
    void TagBox_ValuesChanged(IEnumerable<string> newSelectedObjectTypes) {
        SelectedSpaceObjectTypes = newSelectedObjectTypes;
        var filterCriteria = SelectedSpaceObjectTypes.Count() > 0
            ? new InOperator("TypeOfObject", SelectedSpaceObjectTypes)
            : null;
        TreeList.SetFilterCriteria(filterCriteria);
    }
}

You can apply a filter to a column without resetting the existing filter. Pass a criteria operator object to the SetFieldFilterCriteria(String, CriteriaOperator) method to apply the filter to a particular data field. This method combines filters from different fields with the AND operator.

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" });

Run Demo: TreeList - Filter API

For more information, see the following topic: Filter API in Blazor TreeList.

See Also