DxListBox<TData, TValue>.SetFilterCriteria(CriteriaOperator) Method
Applies a filter to List Box data.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
public void SetFilterCriteria(
CriteriaOperator criteria
)
Parameters
Name | Type | Description |
---|---|---|
criteria | CriteriaOperator | An object that specifies the filter expression. |
Remarks
The Blazor List Box allows you to filter its data in code.
You can create a criteria operator object that specifies the filter expression and pass this object to the SetFilterCriteria
method. For more information about criteria operators, see the following sections:
- Criteria Language Syntax
Criteria Language Syntax - Custom Data Specifics
When a filter is applied, the List Box raises the FilterCriteriaChanged event.
You can call the ClearFilter() method to clear any previously applied filters and apply a new filter to list box data.
The following code creates a toolbar that allows you to apply filter criteria to List Box data and clear filter.
<DxToolbar ItemClick="@OnItemClick">
<Items>
<DxToolbarItem Name="_setFilterCriteria" Text="Set Filter Criteria" Tooltip="Set Filter Criteria" />
<DxToolbarItem Name="_clearFilterCriteria" Text="Clear Filter Criteria" Tooltip="Clear Filter Criteria" />
</Items>
</DxToolbar>
<br/>
<DxListBox @ref="@_listBox" TData=Person TValue=Person Data="Staff.DataSource"
ShowCheckboxes="true"
SelectionMode="@ListBoxSelectionMode.Multiple">
<Columns>
<DxListEditorColumn FieldName="FirstName"></DxListEditorColumn>
<DxListEditorColumn FieldName="LastName"></DxListEditorColumn>
<DxListEditorColumn FieldName="Department"></DxListEditorColumn>
<DxListEditorColumn FieldName="Salary"></DxListEditorColumn>
</Columns>
</DxListBox>
<p class="cw-480 mt-3">
Filter Criteria: <b>@_listBox?.GetFilterCriteria()?.ToString()</b>
</p>
@code {
IListBox<Person, Person> _listBox;
void OnItemClick(ToolbarItemClickEventArgs e) {
switch(e.ItemName) {
case "_setFilterCriteria":
_listBox.SetFilterCriteria(new BinaryOperator(nameof(Person.Salary), 2000, BinaryOperatorType.Greater));
break;
case "_clearFilterCriteria":
_listBox.ClearFilter();
break;
}
}
}
Criteria Language Syntax - Custom Data Specifics
If you bind the List Box to custom data, you can use the following criteria operators.
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" });