Skip to content

Commit bcde505

Browse files
authored
Merge pull request #367 from telerik/multiselect-grouping
docs: document MultiSelect grouping
2 parents 14c85b4 + 5b8adef commit bcde505

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

components/autocomplete/grouping.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ The group headers can stick to the top of the dropdown during scrolling. In othe
2222
<TelerikAutoComplete Data="@Data"
2323
@bind-Value="@SelectedValue"
2424
GroupField="Category.CategoryName"
25-
TextField="ProductName"
26-
ValueField="ProductId"
25+
ValueField="ProductName"
2726
Placeholder="Select a product">
2827
</TelerikAutoComplete>
2928
3029
@code {
3130
public List<Product> Data { get; set; }
32-
public int? SelectedValue { get; set; }
31+
public string SelectedValue { get; set; }
3332
3433
protected override void OnInitialized()
3534
{

components/combobox/grouping.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ The group headers can stick to the top of the dropdown during scrolling. In othe
2828
</TelerikComboBox>
2929
3030
@code {
31-
public List<Product> Data { get; set; }
32-
public int? SelectedValue { get; set; }
31+
public IEnumerable<Product> Data { get; set; }
32+
public int SelectedValue { get; set; }
3333
3434
protected override void OnInitialized()
3535
{

components/dropdownlist/grouping.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ The group headers can stick to the top of the dropdown during scrolling. In othe
2828
</TelerikDropDownList>
2929
3030
@code {
31-
public List<Product> Data { get; set; }
32-
public int? SelectedValue { get; set; }
31+
public IEnumerable<Product> Data { get; set; }
32+
public int SelectedValue { get; set; }
3333
3434
protected override void OnInitialized()
3535
{

components/multiselect/grouping.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Grouping
3+
page_title: MultiSelect - Grouping
4+
description: Grouping in the MultiSelect for Blazor.
5+
slug: components/multiselect/grouping
6+
tags: telerik,blazor,multiselect,group,grouping
7+
published: True
8+
position: 15
9+
---
10+
11+
# MultiSelect Grouping
12+
13+
The MultiSelect component allows users to see the dropdown items grouped in categories. This can improve the user experience and make browsing through the items faster.
14+
15+
To enable MultiSelect grouping, set the `GroupField` parameter to a field name from the model. The MultiSelect will display the corresponding field values as group headers in the dropdown. Nested values of complex object properties are supported (see the example below).
16+
17+
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.
18+
19+
>caption Grouping in the ComboBox
20+
21+
````CSHTML
22+
<TelerikMultiSelect Data="@Data"
23+
@bind-Value="@SelectedProducts"
24+
GroupField="Category.CategoryName"
25+
TextField="ProductName"
26+
ValueField="ProductId"
27+
Placeholder="Select a product">
28+
</TelerikMultiSelect>
29+
30+
@code {
31+
public IEnumerable<Product> Data { get; set; }
32+
public List<int> SelectedProducts { get; set; } = new List<int>();
33+
34+
protected override void OnInitialized()
35+
{
36+
List<Product> products = new List<Product>();
37+
for (int i = 0; i < 20; i++)
38+
{
39+
products.Add(new Product()
40+
{
41+
ProductId = i,
42+
ProductName = $"Product {i}",
43+
Category = new Category() { CategoryId = i % 5, CategoryName = $"Category {i % 5}" }
44+
});
45+
}
46+
47+
Data = products;
48+
49+
base.OnInitialized();
50+
}
51+
52+
public class Product
53+
{
54+
public int ProductId { get; set; }
55+
public string ProductName { get; set; }
56+
public Category Category { get; set; }
57+
}
58+
59+
public class Category
60+
{
61+
public int CategoryId { get; set; }
62+
public string CategoryName { get; set; }
63+
}
64+
}
65+
````
66+
67+
# Notes
68+
69+
* One level of grouping is supported.
70+
* The `DefaultItem` (e.g. "Select item...") is always rendered above the sticky group header in the dropdown.
71+
* A grouped ComboBox will provide a `Groups` property with a single [`GroupDescriptor`](https://docs.telerik.com/blazor-ui/api/Telerik.DataSource.GroupDescriptor) in the [`DataSourceRequest`](https://docs.telerik.com/blazor-ui/api/Telerik.DataSource.DataSourceRequest) argument of its [OnRead event]({%slug components/multiselect/events%}#onread). This will allow the developer to apply grouping with [manual data operations]({%slug components/grid/manual-operations%}).
72+
* `GroupHeaderTemplate` and `GroupItemTemplate` will be introduced in a future version. Currently there is a bug in the Blazor framework that prevents us from supporting them.
73+
* Virtual scrolling with grouping will be supported in a future version.
74+
75+
## See Also
76+
77+
* [Live Demo: MultiSelect Grouping](https://demos.telerik.com/blazor-ui/multiselect/grouping)

0 commit comments

Comments
 (0)