|
| 1 | +--- |
| 2 | +title: Grouping |
| 3 | +page_title: Grid for Blazor | Grouping |
| 4 | +description: Enable and configure grouping in Grid for Blazor |
| 5 | +slug: components/grid/features/grouping |
| 6 | +tags: telerik,blazor,grid,grouping |
| 7 | +published: True |
| 8 | +position: 22 |
| 9 | +--- |
| 10 | + |
| 11 | +# Grid Grouping |
| 12 | + |
| 13 | +The Grid component offers support for grouping. |
| 14 | + |
| 15 | +To enable grouping, set the grid's `Groupable` property to `true`. |
| 16 | + |
| 17 | +Drag a column header to the group panel and the grid will create groups in the data rows based on the available values for that field. An indicator will be shown for the column that is used for grouping. |
| 18 | + |
| 19 | +You can also group by multiple fields and groups for subsequent fields will be nested within their parent groups. When adding a group, you can drag it in the desired position in the list of current groups. |
| 20 | + |
| 21 | +To remove a group setting, click the `[x]` button on its indicator in the group panel. |
| 22 | + |
| 23 | +>caption Enable grouping in Telerik Grid |
| 24 | +
|
| 25 | +````CSHTML |
| 26 | +@using Telerik.Blazor.Components.Grid |
| 27 | +
|
| 28 | +<TelerikGrid Data=@GridData Groupable="true" Pageable="true" Height="400px"> |
| 29 | + <TelerikGridColumns> |
| 30 | + <TelerikGridColumn Field=@nameof(Employee.Name) /> |
| 31 | + <TelerikGridColumn Field=@nameof(Employee.Team) Title="Team" /> |
| 32 | + <TelerikGridColumn Field=@nameof(Employee.IsOnLeave) Title="On Vacation" /> |
| 33 | + </TelerikGridColumns> |
| 34 | +</TelerikGrid> |
| 35 | +
|
| 36 | +@code { |
| 37 | + public List<Employee> GridData { get; set; } |
| 38 | +
|
| 39 | + protected override void OnInitialized() |
| 40 | + { |
| 41 | + GridData = new List<Employee>(); |
| 42 | + var rand = new Random(); |
| 43 | + for (int i = 0; i < 15; i++) |
| 44 | + { |
| 45 | + GridData.Add(new Employee() |
| 46 | + { |
| 47 | + EmployeeId = i, |
| 48 | + Name = "Employee " + i.ToString(), |
| 49 | + Team = "Team " + i % 3, |
| 50 | + IsOnLeave = i % 2 == 0 |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | +
|
| 55 | + public class Employee |
| 56 | + { |
| 57 | + public int EmployeeId { get; set; } |
| 58 | + public string Name { get; set; } |
| 59 | + public string Team { get; set; } |
| 60 | + public bool IsOnLeave { get; set; } |
| 61 | + } |
| 62 | +} |
| 63 | +```` |
| 64 | + |
| 65 | +>caption How groping works in the Telerik grid |
| 66 | +
|
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +## See Also |
| 71 | + |
| 72 | + * [Live Demo: Grid Grouping](https://demos.telerik.com/blazor-ui/grid/grouping) |
| 73 | + |
| 74 | + |
0 commit comments