Blazorise DataGrid: Header Group
Header Group feature for Blazorise DataGrid allows you to easily group a set of defined columns by rendering a top row header which groups the columns by the defined Caption.
Examples
Header Group
You can define columns that can be grouped by assigning the HeaderGroupCaption and enabling ShowHeaderGroupCaptions on the DataGrid.
1 - 10 of 25 items
25 items
<DataGrid TItem="Employee" Data="inMemoryData" ShowPager ShowPageSizes ShowHeaderGroupCaptions> <DataGridColumns> <DataGridColumn DisplayOrder=2 TItem="Employee" Field="@nameof( Employee.LastName )" HeaderGroupCaption="Personal Info" Caption="Last Name" /> <DataGridColumn TextAlignment="TextAlignment.Center" TItem="Employee" Field="@nameof( Employee.Id )" Caption="#" Width="Width.Px( 60 )" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.FirstName )" HeaderGroupCaption="Personal Info" Caption="First Name" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.Zip )" HeaderGroupCaption="Address" Caption="Zip" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.City )" HeaderGroupCaption="Address" Caption="City"> <CaptionTemplate> <Icon Name="IconName.City" /> @context.Caption </CaptionTemplate> </DataGridColumn> <DataGridColumn TItem="Employee" Field="@nameof( Employee.Email )" HeaderGroupCaption="Personal Info" Caption="Email" /> </DataGridColumns> </DataGrid>
@code { private readonly EmployeeData EmployeeData = new(); private List<Employee> inMemoryData; protected override async Task OnInitializedAsync() { inMemoryData = ( await EmployeeData.GetDataAsync().ConfigureAwait( false ) ).Take( 25 ).ToList(); await base.OnInitializedAsync(); } }
Header Group Template
You can define also further customize the look of each header group by defining HeaderGroupCaptionTemplate.
1 - 10 of 25 items
25 items
<DataGrid TItem="Employee" Data="inMemoryData" ShowPager ShowPageSizes ShowHeaderGroupCaptions> <DataGridColumns> <DataGridColumn DisplayOrder=2 TItem="Employee" Field="@nameof( Employee.LastName )" HeaderGroupCaption="PersonalInfo" Caption="Last Name" /> <DataGridColumn TextAlignment="TextAlignment.Center" TItem="Employee" Field="@nameof( Employee.Id )" Caption="#" Width="Width.Px( 60 )" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.FirstName )" HeaderGroupCaption="PersonalInfo" Caption="First Name" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.Zip )" HeaderGroupCaption="Address" Caption="Zip" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.City )" HeaderGroupCaption="Address" Caption="City"> <CaptionTemplate> <Icon Name="IconName.City" /> @context.Caption </CaptionTemplate> </DataGridColumn> <DataGridColumn TItem="Employee" Field="@nameof( Employee.Email )" HeaderGroupCaption="PersonalInfo" Caption="Email" /> </DataGridColumns> <HeaderGroupCaptionTemplate> @if ( context.HeaderGroupCaption == "PersonalInfo" ) { <Strong TextColor="TextColor.Primary">Personal Information</Strong> } else if ( context.HeaderGroupCaption == "Address" ) { <Strong TextColor="TextColor.Success">Address</Strong> } </HeaderGroupCaptionTemplate> </DataGrid>
@code { private readonly EmployeeData EmployeeData = new(); private List<Employee> inMemoryData; protected override async Task OnInitializedAsync() { inMemoryData = ( await EmployeeData.GetDataAsync().ConfigureAwait( false ) ).Take( 25 ).ToList(); await base.OnInitializedAsync(); } }
API
See the API reference for the parameters, events, methods, and related types available to the components covered on this page.