Web Components Grid Multi-Column Headers Overview

    The Ignite UI for Web Components Multi-Column Headers feature in Web Components Grid allows you to group columns by placing them under a common multi-header. Each multi-column headers group in the IgcGridComponent 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 Grid Multi-Column Headers Example

    The declaration of multi-column headers is achieved by wrapping a set of columns into an IgcColumnGroupComponent component with IgcHeaderComponent title information passed.

    <igc-grid allow-filtering="true">
        <igc-column-group header="Contact Information">
            <igc-column sortable="true" resizable="true" field="Phone"></igc-column>
            <igc-column sortable="true" resizable="true" field="Fax"></igc-column>
            <igc-column sortable="true" resizable="true" field="PostalCode"></igc-column>
        </igc-column-group>
    </igc-grid>
    

    For achieving n-th level of nested headers, the declaration above should be followed. So by nesting IgcColumnGroupComponent leads to the desired result.

    <igc-grid height="600px" allow-filtering="true">
        <igc-column-group header="General Information">
            <igc-column movable="true" sortable="true" resizable="true" field="CompanyName"></igc-column>
            <igc-column-group movable="true" header="Person Details">
                <igc-column movable="true" pinned="false" sortable="true" resizable="true" field="ContactName"></igc-column>
                <igc-column movable="true" sortable="true" resizable="true" field="ContactTitle"></igc-column>
            </igc-column-group>
        </igc-column-group>
    </igc-grid>
    

    Every IgcColumnGroupComponent 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 same group.
    When columns/column-groups are not wrapped by current group which means they are top level columns, moving is allowed between whole visible columns.

    <igc-grid height="600px" allow-filtering="true">
        <igc-column-group  movable="true" pinned="true" header="General Information">
            <igc-column movable="true" sortable="true" resizable="true" field="CompanyName"></igc-column>
        </igc-column-group>
        <igc-column sortable="true" resizable="true" field="Phone"></igc-column>
        <igc-column sortable="true" resizable="true" field="Fax"></igc-column>
        <igc-column sortable="true" resizable="true" field="PostalCode"></igc-column>
    </igc-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>
        `;
    }
    

    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:

    <igc-grid class="grid"></igc-grid>
    

    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

    Our community is active and always welcoming to new ideas.