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';
OptionTypeDefaultDescription
groupOn(row) => string[]-Callback returning group path array
defaultExpanded`boolean \number \string \
showRowCountbooleantrueShow row count in group header
indentWidthnumber20Indentation per level (pixels)
fullWidthbooleantrueGroup row spans full width
animation`false \‘slide’ \‘fade’`
accordionbooleanfalseOnly one group open at a time
MethodSignatureDescription
expandGroup(path: string[]) => voidExpand a specific group
collapseGroup(path: string[]) => voidCollapse a specific group
expandAll() => voidExpand all groups
collapseAll() => voidCollapse all groups
isGroupExpanded(path: string[]) => booleanCheck if group is expanded
getGroupState() => GroupStateGet current grouping state
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
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',
})
  • GroupingRowsConfig for all configuration options
  • GroupState for the group state structure

Extends BaseGridPlugin

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

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

static detect(rows: unknown, config: any): boolean
NameTypeDescription
rowsunknown
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

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