Examples › Column grouping
Sometimes a subset of columns is closely related, in which case it makes sense to group their headers under a shared title. You can do this by passing the groups prop to the DataTable instead of columns.
Each group requires the following properties:
id
Used as a key. It can be any string, as long as it is unique among the groups.
A humanized version of this value is used as the group header if notitleis provided.columns
An array of column definitions that are part of this group.
Alternatively, you can provide nestedgroupsinstead ofcolumns— see multilevel column grouping below.
A group also accepts a few optional properties for customization purposes:
title
AReactNodeto render inside the group header. If not specified, theidis humanized to generate a title.textAlign: 'left' | 'center' | 'right'
The text alignment of the group header. It doesn’t affect the alignment of the columns in the group, which you can set individually.className: string
Optional class name to apply to the group header.style
Optional style to apply to the group header.
Can be a style object or a function that receives the current theme and returns a style object.
Groups are hidden if they don’t have any visible columns. This can happen when all of their columns are hidden by the hidden or visibleMediaQuery properties, or when the group has an empty array of columns.
Here is the code used to generate the table above:
Multilevel column grouping
Groups can be nested to create multiple header rows. To do this, provide a groups array instead of columns for a group; each nested group can, in turn, contain either columns or further groups, but not both.
Branches don’t need to have the same depth: if a group containing columns sits at a shallower level than others, its header will span the extra header rows. The order of the leaf columns in the table follows the order in which they appear in the group tree.
Here is the code used to generate the table above:
Head over to the next example to discover more features.












