Skip to main content
All docs
V25.1
  • List Box - Data Shaping

    • 10 minutes to read

    Group Data

    The Blazor ListBox allows you to organize list items into groups. This enhance user experience by allowing users to locate required values faster. To group data, specify the GroupFieldName property. Values from the specified field appear within group headers.

    Note the following specifics:

    • The ListBox supports only one group level.
    • Users cannot collapse groups.
    • Group headers do not take part in search operations.
    • Multi-column ListBox controls also support groups.
    • You can use the GroupHeaderDisplayTemplate property to customize group headers.

    The following code organizes data items into groups based on the Country data source field:

    @inject NwindDataService NwindDataService
    
    <DxListBox Data="@Data"
               @bind-Value="@Value"
               ShowSearchBox="true"
               @bind-SearchText="@SearchText"
               TextFieldName="@nameof(Customer.ContactName)"
               GroupFieldName="@nameof(Customer.Country)">
    </DxListBox>
    
    @code {
        string SearchText { get; set; }
        IEnumerable<Customer> Data { get; set; }
        Customer Value { get; set; }
        protected override async Task OnInitializedAsync() {
            Data = await NwindDataService.GetCustomersAsync();
            Value = Data.FirstOrDefault(x => x.Country == "Argentina");
        }
    }
    

    List Box - Group Data

    Run Demo: List Box – Group Data

    Search and Filter Data

    The Blazor List Box ships with API members that allow you to use search and filter capabilities.

    Use the ShowSearchBox property to display the search box in the List Box component. Once a user enters the text in the search box, the List Box looks for rows with matching values, highlights search results, and filters out all other rows. Search is case-insensitive and applies to cells in visible columns only.

    <DxListBox TData=Person TValue=Person Data="Staff.DataSource"
                ShowSearchBox="true"           
                ShowCheckboxes="true"
                SelectionMode="@ListBoxSelectionMode.Multiple">
        <Columns>
            <DxListEditorColumn FieldName="FirstName"></DxListEditorColumn>
            <DxListEditorColumn FieldName="LastName"></DxListEditorColumn>
            <DxListEditorColumn FieldName="Department"></DxListEditorColumn>
        </Columns>
    </DxListBox>
    
    @code {
        public string SearchText { get; set; }
    }
    

    Search Box Overview

    Run Demo: List Box - Search Box

    Search Text

    You can use the SearchText property to specify the search text in code. Refer to Search Syntax.

    <DxListBox TData=Person TValue=Person Data="Staff.DataSource"
                ShowCheckboxes="true"
                SearchText="Sa"
                SelectionMode="@ListBoxSelectionMode.Multiple">
        <Columns>
            <DxListEditorColumn FieldName="FirstName"></DxListEditorColumn>
            <DxListEditorColumn FieldName="LastName"></DxListEditorColumn>
            <DxListEditorColumn FieldName="Department"></DxListEditorColumn>
        </Columns>
    </DxListBox>
    

    Search Text

    To respond to search text changes, handle the SearchTextChanged event. The event is handled automatically when you use two-way data binding for the SearchText property (@bind-SearchText).

    Set a column’s SearchEnabled property to false to exclude a specific column from search operations.

    If the search text contains multiple words separated by space characters, the words can be treated as a single condition or individual conditions based on the SearchTextParseMode property value.

    Filter Criteria

    The 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(CriteriaOperator) method. To get the applied filter criteria, use the GetFilterCriteria() method.

    For more information about criteria operators, see the following topics:

    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.

    @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>
    <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;
            }
        }
    }
    

    Filter Criteria

    Run Demo: List Box - Filter Criteria

    Disabled Items

    You can disable individual items in the List Box. To do this, use the DisabledFieldName property. The property specifies a Boolean field that stores each item’s enabled or disabled state. Disabled items are grayed out and cannot be selected.

    Note

    Disabled items can improve component usability, but cannot replace adequate security measures. Users may still be able to select disabled items on the client side, so you should implement appropriate security checks in your code.

    @inject NwindDataService NwindDataService
    
    <DxListBox Data="@Products"
               @bind-Values="@SelectedProducts"
               TextFieldName="@nameof(Product.ProductName)"
               DisabledFieldName="@nameof(Product.Discontinued)"
               SelectionMode="ListBoxSelectionMode.Multiple"
               CssClass="cw-400 chi-220">
    </DxListBox>
    
    @code {
        IEnumerable<Product> Products { get; set; }
        IEnumerable<Product> SelectedProducts { get; set; }
        protected override async Task OnInitializedAsync() {
            Products = await NwindDataService.GetProductsAsync();
            SelectedProducts = Products.Take(1);
        }
    }
    

    List Box - Disabled Items

    Run Demo: List Box – Disabled Items