React Grid Multi-Column Headers Overview
The Ignite UI for React Multi-Column Headers feature in React Grid allows you to group columns by placing them under a common multi-header. Each multi-column headers group in the IgrGrid
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.
React Grid Multi-Column Headers Example
The declaration of multi-column headers is achieved by wrapping a set of columns into an IgrColumnGroup
component with IgrHeader
title information passed.
<IgrGrid allowFiltering="true">
<IgrColumnGroup header="Contact Information">
<IgrColumn sortable="true" resizable="true" field="Phone"></IgrColumn>
<IgrColumn sortable="true" resizable="true" field="Fax"></IgrColumn>
<IgrColumn sortable="true" resizable="true" field="PostalCode"></IgrColumn>
</IgrColumnGroup>
</IgrGrid>
For achieving n-th
level of nested headers, the declaration above should be followed. So by nesting IgrColumnGroup
leads to the desired result.
<IgrGrid height="600px" allowFiltering="true">
<IgrColumnGroup header="General Information">
<IgrColumn movable="true" sortable="true" resizable="true" field="CompanyName"></IgrColumn>
<IgrColumnGroup movable="true" header="Person Details">
<IgrColumn movable="true" pinned="false" sortable="true" resizable="true" field="ContactName"></IgrColumn>
<IgrColumn movable="true" sortable="true" resizable="true" field="ContactTitle"></IgrColumn>
</IgrColumnGroup>
</IgrColumnGroup>
</IgrGrid>
Every IgrColumnGroup
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.
<IgrGrid height="600px" allowFiltering="true">
<IgrColumnGroup movable="true" pinned="true" header="General Information">
<IgrColumn movable="true" sortable="true" resizable="true" field="CompanyName"></IgrColumn>
</IgrColumnGroup>
<IgrColumn sortable="true" resizable="true" field="Phone"></IgrColumn>
<IgrColumn sortable="true" resizable="true" field="Fax"></IgrColumn>
<IgrColumn sortable="true" resizable="true" field="PostalCode"></IgrColumn>
</IgrGrid>
Multi-Column Header Template
<IgrColumnGroup header="Contact Information" headerTemplate={groupHeaderTemplate}></IgrColumnGroup>
function groupHeaderTemplate(e: { dataContext: IgrColumnTemplateContext }) {
const column = e.dataContext.column as IgrColumnGroup;
return (
<div>
<span style={{ float: "left" }}>{column.header.toUpperCase()}</span>
</div>
);
}
[!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!
function columnHeaderTemplate(e: { dataContext: IgrColumnTemplateContext }) {
const column = e.dataContext.column as IgrColumnGroup;
return (
<span onClick={onClick}>
<IgrIcon data-draggable="false"></IgrIcon>
</span>
);
}
O exemplo a seguir demonstra como implementar grupos de colunas recolhíveis usando modelos de cabeçalho.
Styling
Além dos temas predefinidos, a grade pode ser ainda mais personalizada ao definir algumas das propriedades CSS disponíveis. Caso você queira alterar algumas das cores, precisa definir uma classe para a grade primeiro:
<IgrGrid className="grid"></IgrGrid>
Em seguida, defina as propriedades CSS relacionadas a esta classe:
.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
- Visão geral da grade
- Virtualização e desempenho
- Paginação
- Filtragem
- Classificação
- Resumos
- Redimensionamento de colunas
- Escolha
- Agrupar por
Nossa comunidade é ativa e sempre acolhedora para novas ideias.