Blazor Grid Multi-Column Headers Overview
The Ignite UI for Blazor Multi-Column Headers feature in Blazor Grid allows you to group columns by placing them under a common multi-header. Each multi-column headers group in the IgbGrid
could be a representation of combinations between other groups or columns. This feature is particularly useful when dealing with large datasets where scrolling horizontally might be cumbersome.
Blazor Grid Multi-Column Headers Example
The declaration of multi-column headers is achieved by wrapping a set of columns into an IgbColumnGroup
component with IgbHeader
title information passed.
<IgbGrid Data=data AllowFiltering=true>
<IgbColumnGroup Header="Contact Information">
<IgbColumn Field="Phone" Sortable=true Resizable=true></IgbColumn>
<IgbColumn Field="Fax" Sortable=true Resizable=true></IgbColumn>
<IgbColumn Field="PostalCode" Sortable=true Resizable=true></IgbColumn>
</IgbColumnGroup>
</IgbGrid>
For achieving n-th
level of nested headers, the declaration above should be followed. So by nesting IgbColumnGroup
leads to the desired result.
<IgbGrid Data=data AllowFiltering=true>
<IgbColumnGroup Header="General Information">
<IgbColumn Field="CompanyName" Sortable=true Resizable=true Movable=true></IgbColumn>
<IgbColumnGroup Header="Person Details" Movable=true>
<IgbColumn Field="ContactName" Sortable=true Resizable=true Movable=true></IgbColumn>
<IgbColumn Field="ContactTitle" Sortable=true Resizable=true Movable=true></IgbColumn>
</IgbColumnGroup>
</IgbColumnGroup>
</IgbGrid>
Every IgbColumnGroup
supports moving, pinning and hiding.
[!Note] When there is a set of columns and column groups, pinning works only for top level column parents. More specifically pinning per nested column groups or columns is not allowed.
Moving between columns and column groups is allowed only when they are at the same level in the hierarchy and both are in the samegroup
.
Whencolumns/column-groups
are not wrapped by currentgroup
which means they are top levelcolumns
, moving is allowed between whole visible columns.
<IgbGrid Data=data AllowFiltering=true>
<IgbColumnGroup Header="General Information" Pinned=true>
<IgbColumn Field="CompanyName" Sortable=true Resizable=true Movable=true></IgbColumn>
</IgbColumnGroup>
<IgbColumn Field="Phone" Sortable=true Resizable=true></IgbColumn>
<IgbColumn Field="Fax" Sortable=true Resizable=true></IgbColumn>
<IgbColumn Field="PostalCode" Sortable=true Resizable=true></IgbColumn>
</IgbGrid>
Multi-Column Header Template
Each of the column groups of the grid can be templated separately. The column group expects RenderFragment
for the HeaderTemplate
property.
The expression is provided with the column group object as a context.
<IgbColumnGroup Header="Address Information" HeaderTemplate="Template">
</IgbColumnGroup>
@code {
public RenderFragment<IgbColumnTemplateContext> Template = (ctx) => {
string value = ctx.Column.Header.ToUpper();
return @<span>@value</span>;
};
}
If you want to re-use a single template for several column groups, you could set the HeaderTemplate
property of the column group like this:
<IgbColumnGroup Header="General Information" HeaderTemplate="Template">
</IgbColumnGroup>
<IgbColumnGroup Header="Address Information" HeaderTemplate="Template">
</IgbColumnGroup>
@code {
public RenderFragment<IgbColumnTemplateContext> Template = (ctx) => {
string value = ctx.Column.Header.ToUpper();
return @<span>@value</span>;
};
}
[!Note] If a header is re-templated and the corresponding column group is movable, you have to set the draggable attribute to false on the templated elements, so that you can handle any of the events that are applied!
@code {
public Dictionary<string, object> DraggableAttributes { get; set; } =
new Dictionary<string, object>()
{
{ "draggable", "false" }
};
public RenderFragment<IgbColumnTemplateContext> Template = (ctx) => {
return @<IgbIcon AdditionalAttributes="DraggableAttributes" @onclick="onClick"/>;
};
}
The following sample demonstrates how to implement collapsible column groups using header templates.
Styling
In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties. In case you would like to change some of the colors, you need to set a class for the grid first:
<IgbGrid class="grid"></IgbGrid>
Then set the related CSS properties to this class:
.grid {
--ig-grid-header-background: #e0f3ff;
--ig-grid-header-text-color: #e41c77;
--ig-grid-header-border-width: 1px;
--ig-grid-header-border-style: solid;
--ig-grid-header-border-color: rgba(0, 0, 0, 0.08);
}
Demo
API References
Additional Resources
- Grid Overview
- Virtualization and Performance
- Paging
- Filtering
- Sorting
- Summaries
- Column Resizing
- Selection
- Group by
Our community is active and always welcoming to new ideas.