Framework:Javascript Data GridAngular Data GridReact Data GridVue Data Grid

React Data Grid: Row Grouping

Row Grouping allows rows to be grouped by columns with the grid performing a 'group by' operation on the rows supplied to the grid. This section introduces Row Grouping and provides links to subsections that cover the various ways Row Grouping can be configured and customised.

The grid can be configured to initially display rows in a grouped state or rows can be grouped programmatically through the grid API's. Users can also manually group rows through the UI as shown below:

Row Grouping

Enabling Default Row Grouping

To group rows by a particular column, enable the rowGroup column property as shown below:

<AgGridReact>
    <AgGridColumn field="country" rowGroup={true} />
    <AgGridColumn field="year" rowGroup={true} />
    <AgGridColumn field="sport" />
    <AgGridColumn field="total" />
</AgGridReact>

In the snippet above, rows will be grouped by country and year as both column definitions have rowGroup=true declared.

Note that the Single Group Column display type is used by default.

The example below demonstrates the default row grouping behaviour. Note the following:

  • There are two active row groups as the supplied country and year column definitions have rowGroup=true declared.
  • A group column is added to the left-hand side of the grid as there are active row groups.
  • The country and year columns are hidden as hide=true on their column definitions.

Row Grouping Customisations

The previous example demonstrated the Default Row Grouping behavior, however extensive Row Grouping customisations are also possible as summarised below:

  • Display Types - compares the different ways row groups can be displayed in the grid.

    • Single Group Column - a single group column is automatically added by the grid for all row groups.
    • Multiple Group Columns - group columns are automatically added by the grid for each row group.
    • Group Rows - group rows are automatically added by the grid containing the row groups instead of group columns.
    • Custom Group Columns - customise how row groups are displayed without using the built-in display types.
  • Row Group Panel - add a panel above the grid to allow users control which columns the rows are grouped by.
  • Group Order - control how row groups are ordered.
  • Sorting Groups - configure and customise how row groups are sorted.
  • Filtering Groups - configure and customise how row groups are filtered.
  • Group Footers - add group footers showing totals for each group level.
  • Opening Groups - control how row groups are expanded and collapsed.
  • Complex Objects - group rows using row data contains complex objects.
  • Unbalanced Groups - group rows when there are null or undefined group values.

API Reference

Row Grouping can be configured using the following grid properties:

groupDisplayType
Specifies how the results of row grouping should be displayed. The options are:
  • 'singleColumn': single group column automatically added by the grid.
  • 'multipleColumns': a group column per row group is added automatically.
  • 'groupRows': group rows are automatically added instead of group columns.
  • 'custom': informs the grid that group columns will be provided.
See Row Grouping - Display Types.
groupDefaultExpanded
number
If grouping, set to the number of levels to expand by default, e.g. 0 for none, 1 for first level only, etc. Set to -1 to expand everything. See Opening Group Levels by Default.
Default: 0
autoGroupColumnDef
Allows specifying the group 'auto column' if you are not happy with the default. If grouping, this column definition is included as the first column in the grid. If not grouping, this column is not included. See Group Column Configuration.
groupSelectsChildren
boolean
When true, if you select a group, the children of the group will also be selected. See Group Selection.
Default: false
groupIncludeFooter
boolean
If grouping, this controls whether to show a group footer when the group is expanded. If true, then by default, the footer will contain aggregate data (if any) when shown and the header will be blank. When closed, the header will contain the aggregate data regardless of this setting (as the footer is hidden anyway). This is handy for 'total' rows, that are displayed below the data when the group is open, and alongside the group when it is closed. See Enabling Group Footers.
Default: false
groupIncludeTotalFooter
boolean
Set to true to show a 'grand total' group footer across all groups. See Enabling Group Footers.
Default: false
groupSuppressBlankHeader
boolean
If true, and showing footer, aggregate data will always be displayed at both the header and footer levels. This stops the possibly undesirable behaviour of the header details 'jumping' to the footer on expand.
Default: false
groupSelectsFiltered
boolean
If using groupSelectsChildren, then only the children that pass the current filter will get selected. See Group Selection.
Default: false
showOpenedGroup
boolean
Shows the open group in the group column for non-group rows. See Showing Open Groups.
Default: false
groupRemoveSingleChildren
boolean
Set to true to collapse groups that only have one child. See Remove Single Children.
Default: false
groupRemoveLowestSingleChildren
boolean
Set to true to collapse lowest level groups that only have one child. See Remove Single Children.
Default: false
groupHideOpenParents
boolean
Set to true to hide parents that are open. When used with multiple columns for showing groups, it can give a more pleasing user experience. See Hide Open Parents.
Default: false
rowGroupPanelShow
string
When to show the 'row group panel' (where you drag rows to group) at the top. See Enabling Row Group Panel.
Default: 'never'
Options: 'never', 'always', 'onlyWhenGrouping'
suppressDragLeaveHidesColumns
boolean
By default, dragging a column out of the grid, i.e. to the Row Group Panel, it will be hidden in the grid. This property prevents the column becoming hidden in the grid. See Keeping Columns Visible.
Default: false
suppressMakeColumnVisibleAfterUnGroup
boolean
By default, when a column is un-grouped, i.e. using the Row Group Panel, it is made visible in the grid. This property stops the column becoming visible again when un-grouping. See Keeping Columns Visible.
Default: false

Next Up

Continue to the next section to learn about the different Row Grouping Display Types.