Descripción general de encabezados de varias columnas de cuadrícula de árbol Web Components
The Ignite UI for Web Components Multi-Column Headers feature in Web Components Tree Grid allows you to group columns by placing them under a common multi-header. Each multi-column headers group in the IgcTreeGridComponent 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.
Web Components Tree Grid Multi-Column Headers Example
The declaration of multi-column headers is achieved by wrapping a set of columns into an columnGroup component with header title information passed.
<igc-tree-grid primaryKey="ID" foreignKey="ParentID">
<igc-column-group header="Contact Information">
<igc-column field="Phone" data-type="String" sortable="true" resizable="true"></igc-column>
<igc-column field="Fax" data-type="String" sortable="true" resizable="true"></igc-column>
<igc-column field="PostalCode" data-type="String" sortable="true" resizable="true"></igc-column>
</igc-column-group>
</igc-tree-grid>
For achieving n-th level of nested headers, the declaration above should be followed. So by nesting columnGroup leads to the desired result.
<igc-tree-grid primary-key="ID" foreign-key="ParentID" moving="true">
<igc-column-group pinned="false" header="General Information">
<igc-column field="HireDate" data-type="date" sortable="true" resizable="true"></igc-column>
<igc-column-group header="Person Details">
<igc-column field="ID" data-type="number" resizable="true" filterable="false"></igc-column>
<igc-column field="Title" data-type="string" sortable="true" resizable="true"></igc-column>
<igc-column field="Age" data-type="number" sortable="true" resizable="true"></igc-column>
</igc-column-group>
</igc-column-group>
</igc-tree-grid>
Every columnGroup 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.
<igc-tree-grid primary-key="ID" foreign-key="ParentID" moving="true">
<igc-column-group header="Contact Information">
<igc-column field="Phone" data-type="String" sortable="true" resizable="true"></igc-column>
</igc-column-group>
<igc-column field="Name" data-type="String" sortable="true" resizable="true"></igc-column>
<igc-column field="Title" data-type="String" sortable="true" resizable="true"></igc-column>
<igc-column field="Age" data-type="Number" sortable="true" resizable="true"></igc-column>
</igc-tree-grid>
Multi-Column Header Template
Each of the column groups of the grid can be templated separately. The following code snippet demonstrates how to use the headerTemplate of a column group:
<igc-column-group id="addressInfo" header="Address Information">
</igc-column-group>
constructor() {
var addresss = this.addresss = document.getElementById('addressInfo') as IgcColumnGroupComponent;
addresss.headerTemplate = this.columnGroupHeaderTemplate;
}
public columnGroupHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
return html`
${ctx.column.header.toUpperCase()}
`;
}
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:
<igc-column-group id="generalInfo" header="General Information">
</igc-column-group>
<igc-column-group id="addressInfo" header="Address Information">
</igc-column-group>
constructor() {
var general = this.general = document.getElementById('generalInfo') as IgcColumnGroupComponent;
var addresss = this.address = document.getElementById('addressInfo') as IgcColumnGroupComponent;
general.headerTemplate = this.columnGroupHeaderTemplate;
addresss.headerTemplate = this.columnGroupHeaderTemplate;
}
public columnGroupHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
return html`
${ctx.column.header.toUpperCase()}
`;
}
[!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!
public columnHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
return html`
<igc-icon draggable="false" @click="${() => this.onClick()}"></igc-icon>
`;
}
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:
<igc-tree-grid class="grid"></igc-tree-grid>
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
Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.