React Tree Grid Multi-Column Headers Overview

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

    EXAMPLE
    DATA
    TSX
    CSS

    Like this sample? Get access to our complete Ignite UI for React toolkit and start building your own apps in minutes. Download it for free.

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

    <IgrTreeGrid primaryKey="ID" foreignKey="ParentID">
        <IgrColumnGroup header="Contact Information">
            <IgrColumn sortable="true" resizable="true" field="Phone" dataType={GridColumnDataType.String}></IgrColumn>
            <IgrColumn sortable="true" resizable="true" field="Fax" dataType={GridColumnDataType.String}></IgrColumn>
            <IgrColumn sortable="true" resizable="true" field="PostalCode" dataType={GridColumnDataType.String}></IgrColumn>
        </IgrColumnGroup>
    </IgrTreeGrid>
    tsx

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

    <IgrTreeGrid primaryKey="ID" foreignKey="ParentID" moving="true">
        <IgrColumnGroup pinned="false" header="General Information">
            <IgrColumn field="HireDate" sortable="true" resizable="true" dataType={GridColumnDataType.Date}></IgrColumn>
            <IgrColumnGroup header="Person Details">
                <IgrColumn field="ID" resizable="true" filterable="true" dataType={GridColumnDataType.Number}></IgrColumn>
                <IgrColumn field="Title" sortable="true" resizable="true" dataType={GridColumnDataType.String}></IgrColumn>
                <IgrColumn field="Age" sortable="true" resizable="true" dataType={GridColumnDataType.Number}></IgrColumn>
            </IgrColumnGroup>
        </IgrColumnGroup>
    </IgrTreeGrid>
    tsx

    Every IgrColumnGroup supports moving, pinning and hiding.

    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.

    <IgrTreeGrid primaryKey="ID" foreignKey="ParentID" moving="true">
        <IgrColumnGroup header="Contact Information">
            <IgrColumn field="Phone" movable="true" sortable="true" resizable="true" dataType={GridColumnDataType.String}></IgrColumn>
        </IgrColumnGroup>
        <IgrColumn field="Name" sortable="true" resizable="true" dataType={GridColumnDataType.String}></IgrColumn>
        <IgrColumn field="Title" sortable="true" resizable="true" dataType={GridColumnDataType.String}></IgrColumn>
        <IgrColumn field="Age" sortable="true" resizable="true" dataType={GridColumnDataType.Number}></IgrColumn>
    </IgrTreeGrid>
    tsx

    Multi-Column Header Template

    <IgrColumnGroup header="Contact Information" headerTemplate={groupHeaderTemplate}></IgrColumnGroup>
    tsx
    function groupHeaderTemplate(e: { dataContext: IgrColumnTemplateContext }) {
        const column = e.dataContext.column as IgrColumnGroup;
        return (
          <div>
            <span style={{ float: "left" }}>{column.header.toUpperCase()}</span>
          </div>
        );
    }
    tsx

    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>
        );
    }
    tsx

    The following sample demonstrates how to implement collapsible column groups using header templates.

    EXAMPLE
    DATA
    TSX
    CSS

    Ignite UI for React | CTA Banner

    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:

    <IgrTreeGrid className="grid"></IgrTreeGrid>
    tsx

    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);
    }
    css

    Demo

    EXAMPLE
    DATA
    TSX
    CSS

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.