Skip to main content

DxTagBox<TData, TValue>.Data Property

Specifies a strongly typed collection that supplies TagBox data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public IEnumerable<TData> Data { get; set; }

Property Value

Type Description
IEnumerable<TData>

A data collection.

Remarks

Strongly Typed Collection

Use the Data property to bind the TagBox to a strongly typed collection. Initialize this collection in the OnInitialized lifecycle method or before this method is invoked. The corresponding data items are displayed in the editor’s drop-down list.

The editor’s tags are specified by the Tags property. Once a user selects an item from the drop-down list, the corresponding item is hidden from the list and added to the editor’s tags. To display selected items, set HideSelectedItems to false.

To allow users to specify custom tags that are not stored in a bound data source, set the AllowCustomTags property to true.

<DxTagBox Data="@Cities"
          NullText="Select city..."
          TData="string"
          TValue="string"
          AllowCustomTags="true"
          @bind-Tags="@Tags"
          ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"/>

@code {
    IEnumerable<string> Cities { get; set; } = new List<string>() {
        "London",
        "Berlin",
        "Paris"
    };
    IEnumerable<string> Tags { get; set; } = new List<string>() {
        "London",
        "New York"
    };
}

TagBox Custom Tags

Use the DataAsync property instead of the Data property if a strongly typed collection is loaded asynchronously (for instance, from an HTTP request). Use the CustomData property if your data is stored on a remote service and is loaded through a Web API.

Run Demo: TagBox - Overview

Custom Object Collection

You can bind the TagBox to a data collection (Data) that stores custom objects (IEnumerable<CustomType>). The Values collection can also contain custom objects. In this case, you need to override the custom object’s Equals method. Otherwise, the TagBox uses the default Equals method implementation to compare items in the Data and Values collections. This method determines whether two object instances are equal. The compared items will not be equal if they are different instances (even if they have exactly the same properties). As a result, the component will not display the selected items.

You also need to set the TextFieldName property. It specifies the custom object’s field name that returns strings to be shown in the TagBox. If the TextFieldName property is not specified, the TagBox component searches for a Text field in the data source and uses this field as a text field. Otherwise, the TagBox is populated with CustomType.ToString() values.

@using BlazorApp.Data

<DxTagBox Data="@Staff.DataSource"
          @bind-Values="@SelectedStaff"
          TextFieldName="@nameof(Person.Text)">
</DxTagBox>

@code {
    IEnumerable<Person> SelectedStaff { get; set; } = new List<Person>() { Staff.DataSource[0] };
}

TagBox Overview

See Also