Descripción general de los encabezados de varias columnas de cuadrícula de Blazor
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 Header 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-groupsare not wrapped by currentgroupwhich 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"/>;
};
}
El siguiente ejemplo demuestra cómo implementar grupos de columnas contraíbles utilizando plantillas de encabezado.
Styling
Además de los temas predefinidos, la cuadrícula se puede personalizar aún más configurando algunas de las propiedades CSS disponibles. En caso de que desee cambiar algunos de los colores, primero debe establecer una clase para la cuadrícula:
<IgbGrid class="grid"></IgbGrid>
Luego establezca las propiedades CSS relacionadas con esta clase:
.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
- Descripción general de la cuadrícula
- Virtualización y rendimiento
- Paginación
- Filtración
- Clasificación
- resúmenes
- Cambio de tamaño de columna
- Selección
- Agrupar por
Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.