Skip to main content
All docs
V24.1

Filter API in Blazor TreeList

  • 4 minutes to read

The TreeList component allows you to apply filters in the UI and in code. This topic explains how to apply filters in code.

Run Demo: TreeList - Filter API

Note

When the TreeList component is bound to a GridDevExtremeDataSource, the TreeList displays a maximum of 500 rows that match the current filter to improve performance.

Apply Filter Criteria

Use the following methods to apply filter criteria to a column or to specify criteria for all of the TreeList’s data. When you specify filter criteria for specific columns, the TreeList uses the AND operator to apply filters to different columns at the same time. For more information about criteria operators, see the following topic: Criteria Language Syntax.

FilterBy(String, TreeListFilterRowOperatorType, Object)
Filters TreeList data by individual TreeList column values.
SetFieldFilterCriteria(String, CriteriaOperator)
Applies a filter to the specified data field, including fields not displayed in the TreeList.
SetFilterCriteria(CriteriaOperator)
Applies a filter to treelist data. When you call this method, the treelist clears all filters applied previously.

When a filter is applied, the TreeList raises the FilterCriteriaChanged event and displays the specified filter value in the filter row.

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

Get the Applied Filter Criteria

Call the following methods to get the applied filter criteria:

GetFilterCriteria()
Returns the criteria operator applied to the TreeList.
GetFieldFilterCriteria(String)
Returns the criteria operator applied to the specified data field.

Clear the Applied Filter Criteria

Call the following methods to clear a specific column filter condition or to remove all applied filter conditions:

  • Pass the null value to the FilterBy(String, TreeListFilterRowOperatorType, Object) method to clear filter criteria applied to the specified column.
    @* Clears the "Product Name" Filter Condition *@
    <DxButton Click="@(() => TreeList.FilterBy("ProductName", TreeListFilterRowOperatorType.Contains, null))" Text="Clear" />
    
  • Pass the null value to the SetFieldFilterCriteria(String, CriteriaOperator) method to clear filter criteria applied to the specified data field.
    @* Clears the "Product Name" Filter Condition *@
    <DxButton Click="@(() => TreeList.SetFieldFilterCriteria("ProductName", null))" Text="Clear" />
    
  • Pass the null value to the SetFilterCriteria(CriteriaOperator) method to clear all filter criteria applied to treelist data.

    @* Clears Every Filter Condition *@
    <DxButton Click="@(() => TreeList.SetFilterCriteria(null))" Text="Clear" />
    
  • Call the ClearFilter() method to clear all filter criteria applied to treelist data.

    @* Clears Every Filter Condition *@
    <DxButton Click="@(() => TreeList.ClearFilter())" Text="Clear" />