JavaScript Data GridRow Grouping - Grouping Data

Enterprise

Enable grouping on a column to group rows by equivalent values.

Enabling Row Grouping

Row Grouping is enabled by setting rowGroup to true on one or more Column Definition. Parent rows are then introduced for each unique value in that column, containing the rows with that value.

The example above uses the following configuration to group rows by their country values:

const gridOptions = {
    columnDefs: [
        { field: 'country', rowGroup: true },
        // ...other column definitions
    ],

    // other grid options ...
}

Grouping by Multiple Columns

When grouping on multiple columns using rowGroup, the order of columns within the column definitions is used to determine which column to group by first. This can be overridden with a custom order by providing the rowGroupIndex property in each grouped columns definition.

The example above demonstrates the following configuration for grouping rows by year first, and country second:

const gridOptions = {
    columnDefs: [
        { field: 'country', rowGroupIndex: 1 },
        { field: 'year', rowGroupIndex: 0 },
        // ...other column definitions
    ],

    // other grid options ...
}

Grouping on Object Data

When grouping on object data, the grid needs a way to compare items to determine if they are equivalent. Setting a keyCreator on the grouped column definition provides the grid with string keys it can compare.

keyCreator
Function
Function to return a string key for a value. This string is used for grouping, Set filtering, and searching within cell editor dropdowns. When filtering and searching the string is exposed to the user, so make sure to return a human-readable value.

The following example uses a custom set of rows, each containing an athlete field that maps to objects with id and name properties.

This demonstrates the following configuration for grouping rows by the athlete objects by their id property:

const gridOptions = {
    columnDefs: [
        {
            field: 'athlete',
            rowGroup: true,
            keyCreator: (params) => params.value.id,
            valueFormatter: (params) => params.value.name,
        },
        // ...other column definitions
    ],

    // other grid options ...
}

Grouping on Null and Undefined Data

When grouping null, undefined or "" (empty string) values the grid will group these together under the heading (Blanks) as the final group.

By setting the groupAllowUnbalanced property to true, the grid will instead display these rows without a group.

To enable unbalanced grouping, the following configuration is used:

const gridOptions = {
    groupAllowUnbalanced: true,

    // other grid options ...
}

Hiding Parents of Individual Rows

Groups with only a single child can be hidden from the grid by setting the groupHideParentOfSingleChild grid option to true. To remove only groups with a single leaf child, set this option to "leafGroupsOnly" instead.

Filtering does not impact which groups get removed. Only groups containing a single child prior to filtering being applied are removed.

The following is an example of the configuration used to hide all parents of a single row:

const gridOptions = {
    groupHideParentOfSingleChild: true,

    // other grid options ...
}

The properties groupHideParentOfSingleChild and groupHideOpenParents are mutually exclusive.

Next Up

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