ComboBox Grouping
The ComboBox component allows users to see the listed items grouped in categories. This can improve the user experience and make browsing through the items faster.
To enable ComboBox grouping, set the GroupField
parameter to a field name from the model. The ComboBox will display the corresponding field values as group headers in the dropdown. Nested values of complex object properties are supported (see the example below).
The group headers can stick to the top of the dropdown during scrolling. In other words, users will always know which is the group of the current topmost items in the scrollable list.
<TelerikComboBox Data="@Data"
@bind-Value="@SelectedValue"
GroupField="Category.CategoryName"
TextField="ProductName"
ValueField="ProductId"
Placeholder="Select a product">
</TelerikComboBox>
@code {
public IEnumerable<Product> Data { get; set; }
public int SelectedValue { get; set; }
protected override void OnInitialized()
{
List<Product> products = new List<Product>();
for (int i = 0; i < 20; i++)
{
products.Add(new Product()
{
ProductId = i,
ProductName = $"Product {i}",
Category = new Category() { CategoryId = i % 5, CategoryName = $"Category {i % 5}" }
});
}
Data = products;
base.OnInitialized();
}
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public Category Category { get; set; }
}
public class Category
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
}
}
Notes
- One level of grouping is supported.
- A grouped ComboBox will provide a
Groups
property with a singleGroupDescriptor
in theDataSourceRequest
argument of its OnRead event. This will allow the developer to apply grouping with manual data operations.