React Row Grouping

    The Ignite UI for React Data Table / Data Grid lets you group rows into a ‘sticky header’ Row Group. This is similar to the Group By feature in Microsoft Outlook, which is an easy way to visually group data based on your own criteria.

    React Row Grouping Example

    Multiple Groups

    import { IgrColumnGroupDescription } from 'igniteui-react-grids';
    import { ListSortDirection } from 'igniteui-react-core';
    
    public componentDidMount() {
        window.addEventListener('load', this.onLoad);
    }
    
    public onLoad() {
        const state = new IgrColumnGroupDescription();
        state.field = "Country";
        state.displayName = "Location";
        state.sortDirection = ListSortDirection.Descending;
        const city = new IgrColumnGroupDescription();
        city.field = "City";
        city.displayName = "";
        const income = new IgrColumnGroupDescription();
        income.field = "Income";
        income.displayName = "Income";
    
        this.grid.groupDescriptions.add(state);
        this.grid.groupDescriptions.add(city);
        this.grid.groupDescriptions.add(income);
    }
    

    Hierarchical Groups

    The groupHeaderDisplayMode property allows the groups to be hierarchical. By default, each group description that is added gets aggregated together. Setting the groupHeaderDisplayMode to Split will create a section header for ever group defined in groupDescriptions property of the IgrDataGrid.

    import { DataSourceSectionHeaderDisplayMode } from 'igniteui-react-core';
    
    public componentDidMount() {
        // ...
        this.grid.groupHeaderDisplayMode = DataSourceSectionHeaderDisplayMode.Split;
    }
    

    Collapsable Groups

    Also, the IgrDataGrid can display a toggle on each group section to allow the end user to expand or collapse the grouped data via the isGroupCollapsable property.

    public componentDidMount() {
        // ...
        this.grid.isGroupCollapsable = true;
    }
    

    Summary

    For your convenience, all above code snippets are combined into one code block below that you can easily copy to your project.

    import { IgrColumnGroupDescription } from 'igniteui-react-grids';
    import { ListSortDirection } from 'igniteui-react-core';
    import { DataSourceSectionHeaderDisplayMode } from 'igniteui-react-core';
    
    public componentDidMount() {
        window.addEventListener('load', this.onLoad);
    }
    
    public onLoad() {
        const state = new IgrColumnGroupDescription();
        state.field = "Country";
        state.displayName = "Location";
        state.sortDirection = ListSortDirection.Descending;
        const city = new IgrColumnGroupDescription();
        city.field = "City";
        city.displayName = "";
        const income = new IgrColumnGroupDescription();
        income.field = "Income";
        income.displayName = "Income";
    
        this.grid.groupDescriptions.add(state);
        this.grid.groupDescriptions.add(city);
        this.grid.groupDescriptions.add(income);
    
        this.grid.isGroupCollapsable = true;
        this.grid.groupHeaderDisplayMode = DataSourceSectionHeaderDisplayMode.Split;
    }