Skip to content

GroupingRowsPlugin

Row Grouping Plugin for tbw-grid

Organizes rows into collapsible hierarchical groups. Perfect for organizing data by category, department, status, or any other dimension—or even multiple dimensions for nested grouping. Includes aggregation support for summarizing group data.

import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';
PropertyDefaultDescription
--tbw-group-indent-width1.25emIndentation per group level
--tbw-grouping-rows-bgvar(--tbw-color-panel-bg)Group row background
--tbw-grouping-rows-count-colorvar(--tbw-color-fg-muted)Count badge color
--tbw-animation-duration200msExpand/collapse animation
OptionTypeDescription
groupOn?(row: any) => anyCallback to determine group path for a row. Return an array of group keys, a single key, null/false to skip grouping.
groups?GroupDefinition[]Pre-defined group structure for server-side grouping.
defaultExpanded?DefaultExpandedValueDefault expanded state for group rows. - true: Expand all groups initially - false: Collapse all groups initially (default) - number: Expand group at this index (0-based) - string: Expand group with this key (composite key format: “parent
groupRowRenderer?(params: GroupRowRenderParams) => string | void | HTMLElementCustom group row renderer - takes full control of group row rendering
showRowCount?booleanShow row count in group headers (default: true)
indentWidth?numberIndent width per depth level in pixels (default: 20)
aggregators?AggregatorMapAggregators for group row cells by field name
formatLabel?(value: any, depth: number, key: string) => stringCustom format function for group label
fullWidth?booleanWhether to render group row as full-width spanning cell (default: true)
animation?ExpandCollapseAnimationAnimation style for expanding/collapsing groups. - false: No animation - 'slide': Slide animation (default) - 'fade': Fade animation
accordion?booleanAccordion mode - only one group can be expanded at a time. Expanding a group will automatically collapse all other groups at the same depth.
groupRowHeight?numberHeight of group header rows in pixels. Used by the variable row height system to provide consistent heights for group rows without needing to measure them.
import { queryGrid } from '@toolbox-web/grid';
import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Employee' },
{ field: 'department', header: 'Department' },
{ field: 'salary', header: 'Salary', type: 'currency' },
],
plugins: [
new GroupingRowsPlugin({
groupOn: (row) => [row.department],
showRowCount: true,
defaultExpanded: false,
}),
],
};
new GroupingRowsPlugin({
groupOn: (row) => [row.region, row.department, row.team],
indentWidth: 24,
animation: 'slide',
})

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

PropertyTypeDescription
dependenciesobject[]Optional dependency on MultiSort for coordinated sort management. When MultiSort is loaded, GroupingRows queries its sort model to determine group header ordering. Without it, falls back to core sort state.

Auto-detect grouping configuration from grid config. Called by plugin system to determine if plugin should activate.

static detect(rows: readonly any[], config: any): boolean
NameTypeDescription
rowsreadonly any[]
configany

Expand all groups.

expandAll(): void

Collapse all groups.

collapseAll(): void

Toggle expansion of a specific group. In accordion mode, expanding a group will collapse all sibling groups.

toggle(key: string): void
NameTypeDescription
keystringThe group key to toggle

Check if a specific group is expanded.

isExpanded(key: string): boolean
NameTypeDescription
keystringThe group key to check

boolean - Whether the group is expanded


Expand a specific group.

expand(key: string): void
NameTypeDescription
keystringThe group key to expand

Collapse a specific group.

collapse(key: string): void
NameTypeDescription
keystringThe group key to collapse

Get the current group state.

getGroupState(): GroupState

GroupState - Group state information


Get the total count of visible rows (including group headers).

getRowCount(): number

number - Number of visible rows


Refresh the grouped row model. Call this after modifying groupOn or other config options.

refreshGroups(): void

Get current expanded group keys.

getExpandedGroups(): string[]

string[] - Array of expanded group keys


Get the flattened row model.

getFlattenedRows(): RenderRow[]

RenderRow[] - Array of render rows (groups + data rows)


Check if grouping is currently active.

isGroupingActive(): boolean

boolean - Whether grouping is active


Set the groupOn function dynamically.

setGroupOn(fn: (row: any) => any | undefined): void
NameTypeDescription
fn(row: any) => any | undefinedThe groupOn function or undefined to disable

Replace auto-detected groups with an externally provided group structure.

When groups are set, the plugin switches to pre-defined mode — groupOn is ignored and the plugin renders the provided group headers instead. Row data for each group must be populated via setGroupRows.

setGroups(groups: GroupDefinition[]): void
NameTypeDescription
groupsGroupDefinition[]Array of group definitions, or empty array to clear

Get the current pre-defined group structure.

Returns the groups set via setGroups, received from datasource:data, or the groups config array. Returns an empty array when using groupOn-based grouping.

getGroups(): GroupDefinition[]

GroupDefinition[] - Current group definitions


Populate row data for an expanded group.

Call this in response to a group-expand event after fetching rows from the server. The plugin will re-render to show the rows.

When ServerSidePlugin is loaded, this is handled automatically via datasource:children events — you only need this for the imperative API.

setGroupRows(groupKey: string, rows: unknown[]): void
NameTypeDescription
groupKeystringThe group key to populate
rowsunknown[]The row data for this group

Toggle loading indicator for a group.

When loading is true, the group shows a loading spinner instead of row data. Call with false after rows are loaded (also cleared by setGroupRows).

setGroupLoading(groupKey: string, loading: boolean): void
NameTypeDescription
groupKeystringThe group key
loadingbooleanWhether the group is loading

Clear cached row data for one or all groups.

Use when the server data has changed and groups need to be re-fetched on next expand.

clearGroupRows(groupKey: string): void
NameTypeDescription
groupKeystringSpecific group key to clear, or omit to clear all

AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt