DxTreeList.SetFieldFilterCriteria(String, CriteriaOperator) Method
Applies a filter to the specified data field.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
public void SetFieldFilterCriteria(
string fieldName,
CriteriaOperator criteria
)
Parameters
Name | Type | Description |
---|---|---|
fieldName | String | The field name. |
criteria | CriteriaOperator | The filter expression. |
Remarks
Call the SetFieldFilterCriteria
method to filter TreeList data in code.
To apply a filter to a data field, create a criteria operator object that specifies the filter expression and pass this object to the SetFieldFilterCriteria
method. When you call this method, the TreeList uses the AND
operator to combine filters for different fields. You can filter TreeList data by every data source field, including the fields that are 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> × 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> × 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.Any()
? new InOperator("TypeOfObject", SelectedSpaceObjectTypes)
: null;
TreeList.SetFieldFilterCriteria("TypeOfObject", filterCriteria);
}
}
You can call the SetFilterCriteria(CriteriaOperator) method to clear any previously applied filters and apply a new filter to TreeList data.
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
andIsNullOrEmpty
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
, andContains
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" });
For more information, see the following topic: Filter API in Blazor TreeList.