|
| 1 | +--- |
| 2 | +title: Removing Group Indent in Grid for Blazor |
| 3 | +description: This article demonstrates how to remove the group indent in the Grid for Blazor by overriding the default theme styles. |
| 4 | +type: how-to |
| 5 | +page_title: How to Remove Group Indentation in Blazor Grid |
| 6 | +slug: grid-kb-remove-group-indent |
| 7 | +tags: grid, blazor, grouping, indentation |
| 8 | +res_type: kb |
| 9 | +ticketid: 1684110 |
| 10 | +--- |
| 11 | + |
| 12 | +## Description |
| 13 | + |
| 14 | +This knowledge base article also answers the following questions: |
| 15 | + |
| 16 | +- Is there a way to remove the group indent and adjust the spacing without compromising the Grid behavior? |
| 17 | +- How can I customize the grouping appearance in a Blazor Grid? |
| 18 | +- How to hide the group indent and group header icons in a Blazor Grid? |
| 19 | +- What is the best way to adjust the appearance of grouped headers in a Blazor Grid? |
| 20 | + |
| 21 | +## Environment |
| 22 | + |
| 23 | +<table> |
| 24 | + <tbody> |
| 25 | + <tr> |
| 26 | + <td>Product</td> |
| 27 | + <td>Grid for Blazor</td> |
| 28 | + </tr> |
| 29 | + </tbody> |
| 30 | +</table> |
| 31 | + |
| 32 | +## Solution |
| 33 | + |
| 34 | +To remove the group indent in the [Grid for Blazor](slug:components/grid/overview) and adjust the appearance of grouped headers, you will need to override the default theme styles. This solution involves applying custom CSS to the Grid. Run the example below to remove the default grouping indentation: |
| 35 | + |
| 36 | +````RAZOR` |
| 37 | +<TelerikGrid Data=@GridData |
| 38 | + Groupable="true" |
| 39 | + Pageable="true" |
| 40 | + Height="400px" |
| 41 | + Class="custom-grouping"> |
| 42 | + <GridColumns> |
| 43 | + <GridColumn Field=@nameof(Employee.Name) Groupable="false" /> |
| 44 | + <GridColumn Field=@nameof(Employee.Team) Title="Team" /> |
| 45 | + <GridColumn Field=@nameof(Employee.IsOnLeave) Title="On Vacation" /> |
| 46 | + </GridColumns> |
| 47 | +</TelerikGrid> |
| 48 | + |
| 49 | +<style> |
| 50 | + .custom-grouping.k-grid .k-group-col { |
| 51 | + width: 0; |
| 52 | + } |
| 53 | + |
| 54 | + .custom-grouping.k-grid .k-grouping-row .k-icon { |
| 55 | + display: none; |
| 56 | + } |
| 57 | +</style> |
| 58 | + |
| 59 | +@code { |
| 60 | + private List<Employee>? GridData { get; set; } |
| 61 | + |
| 62 | + protected override void OnInitialized() |
| 63 | + { |
| 64 | + GridData = new List<Employee>(); |
| 65 | + var rand = new Random(); |
| 66 | + for (int i = 0; i < 15; i++) |
| 67 | + { |
| 68 | + GridData.Add(new Employee() |
| 69 | + { |
| 70 | + EmployeeId = i, |
| 71 | + Name = "Employee " + i.ToString(), |
| 72 | + Team = "Team " + i % 3, |
| 73 | + IsOnLeave = i % 2 == 0 |
| 74 | + }); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + public class Employee |
| 79 | + { |
| 80 | + public int EmployeeId { get; set; } |
| 81 | + public string Name { get; set; } = string.Empty; |
| 82 | + public string Team { get; set; } = string.Empty; |
| 83 | + public bool IsOnLeave { get; set; } |
| 84 | + } |
| 85 | +} |
| 86 | +```` |
| 87 | +
|
| 88 | +## See Also |
| 89 | +
|
| 90 | +- [Grid Overview](slug:components/grid/overview) |
| 91 | +- [Customizing Theme Styles](slug:override-theme-styles) |
0 commit comments