Skip to main content
All docs
V25.2
  • TagBox - Data Shaping

    • 6 minutes to read

    Group Data

    The Blazor TagBox 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 TagBox supports only one group level.
    • Users cannot collapse groups.
    • Group headers do not take part in search operations.
    • Multi-column TagBox 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
    
    <DxTagBox Data="@Data"
              @bind-Values="@Values"
              TextFieldName="@nameof(Customer.ContactName)"
              GroupFieldName="@nameof(Customer.Country)"
              SearchMode="@ListSearchMode.AutoSearch"
              SearchFilterCondition="@ListSearchFilterCondition.Contains"
              InputId="tbGrouping">
    </DxTagBox>
    
    @code {
        IEnumerable<Customer> Data { get; set; }
        IEnumerable<Customer> Values { get; set; }
        protected override async Task OnInitializedAsync() {
            Data = await NwindDataService.GetCustomersAsync();
            Values = Data.Where(x => x.Country == "Argentina").Take(1);
        }
    }
    

    TagBox - Group Data

    Run Demo: TagBox – Group Data

    Search and Filter Data

    When a user enters text in the edit box, the TagBox searches for this text, filters items based on the search string, and highlights matches. Users can use special characters to create composite criteria. Refer to the following section for more information: Search Syntax.

    You can use the following API members to configure search and filter capabilities:

    • SearchMode — Specifies the search mode. You can set this property to Disabled to prevent users from text searching.
    • SearchFilterCondition — Specifies the search and filter condition (Contains/Default, Equals, or StartsWith).
    • SearchTextParseMode — Specifies how the component combines words in the search query. If the search text contains multiple words separated by spaces, words can be treated as single or individual conditions. The GroupWordsByAnd, GroupWordsByOr, and ExactMatch modes are available.
    • SearchEnabled - Specifies whether the component can search text in cells of the current column.
    • SearchDelay - Specifies the delay between a user’s last input in the edit box and the initiation of the search.
    <DxTagBox Data="Staff.DataSource" 
              @bind-Values="@Values"
              TextFieldName="@nameof(Person.FirstName)"
              ValueFieldName="@nameof(Person.Id)"
              SearchMode="ListSearchMode.AutoSearch"
              SearchFilterCondition="ListSearchFilterCondition.Contains">
        <Columns>
            <DxListEditorColumn FieldName="FirstName"></DxListEditorColumn>
            <DxListEditorColumn FieldName="LastName"></DxListEditorColumn>
            <DxListEditorColumn FieldName="Department" SearchEnabled="false"></DxListEditorColumn>
        </Columns>
    </DxTagBox>
    
    @code{
        IEnumerable<int> Values { get; set; }
    }
    

    When a user types text into the edit box, the TagBox filters and highlights search results.

    TagBox - Filter Data

    Run Demo: TagBox - Search and Filter Data

    Note

    If you use the EditBoxDisplayTemplate property and need to enable filter mode, you should add a DxInputBox object to the template markup.

    Disabled Items

    You can disable individual items in the TagBox drop-down list. 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 users cannot select them.

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

    TagBox - Disabled Items

    Run Demo: TagBox – Disabled Items