blazor-devexpress-dot-blazor-dot-dxlistbox-2-91b2cc1b.md
Returns the filter criteria applied to List Box data.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public CriteriaOperator GetFilterCriteria()
| Type | Description |
|---|---|
| CriteriaOperator |
An object that specifies the filter expression.
|
You can use the SetFilterCriteria(CriteriaOperator) method to apply filter criteria to List Box data. To get the applied filter criteria, use the GetFilterCriteria method.
@using DevExpress.Data.Filtering
<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>
<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;
}
}
}
namespace StaffData {
public static class Staff {
private static readonly Lazy<List<Person>> dataSource = new Lazy<List<Person>>(() =>
{
Random rnd = new Random();
var dataSource = new List<Person>() {
new Person() { Id = 0 , FirstName = "John John", LastName = "Heart", Department = Department.Electronics, Salary = GetRandomSalary(rnd) },
new Person() { Id = 1 , FirstName = "Samantha", LastName = "Bright", Department = Department.Motors, Salary = GetRandomSalary(rnd) },
new Person() { Id = 2 , FirstName = "Arthur", LastName = "Miller", Department = Department.Software, Salary = GetRandomSalary(rnd) },
new Person() { Id = 3 , FirstName = "Robert", LastName = "Reagan", Department = Department.Electronics, Salary = GetRandomSalary(rnd) },
new Person() { Id = 4 , FirstName = "Greta", LastName = "Sims", Department = Department.Motors, Salary = GetRandomSalary(rnd) },
new Person() { Id = 5 , FirstName = "Brett", LastName = "Wade", Department = Department.Software, Salary = GetRandomSalary(rnd) },
new Person() { Id = 6 , FirstName = "Sandra", LastName = "Johnson", Department = Department.Electronics, Salary = GetRandomSalary(rnd) },
new Person() { Id = 7 , FirstName = "Edward", LastName = "+Holmes", Department = Department.Motors, Salary = GetRandomSalary(rnd) },
new Person() { Id = 8 , FirstName = "Barbara", LastName = "Banks", Department = Department.Software, Salary = GetRandomSalary(rnd) },
new Person() { Id = 9 , FirstName = "Kevin", LastName = "Carter", Department = Department.Electronics, Salary = GetRandomSalary(rnd) },
new Person() { Id = 10, FirstName = "Cynthia", LastName = "Stanwick", Department = Department.Motors, Salary = GetRandomSalary(rnd) },
new Person() { Id = 11, FirstName = "Sam", LastName = "Hill", Department = Department.Electronics, Salary = GetRandomSalary(rnd) },
};
return dataSource;
});
public static List<Person> DataSource { get { return dataSource.Value; } }
}
public class Person {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Department Department { get; set; }
public string Text => $"{FirstName} {LastName} ({Department} Dept.)";
public decimal Salary { get; set; }
public DateTime BirthDate { get; set; }
public override bool Equals(object obj) {
if (obj is Person typedObj) {
return (this.Id == typedObj.Id) && (this.FirstName == typedObj.FirstName) && (this.LastName == typedObj.LastName)
&& (this.Department == typedObj.Department);
}
return base.Equals(obj);
}
}
static decimal GetRandomSalary(Random rnd) {
return rnd.Next(1000, 3000);
}
public enum Department { Motors, Electronics, Software }
}
See Also
DxListBox<TData, TValue> Class