Skip to content

useTableGroupedRows

@astryxdesign/core v0.7.1 · useTableGroupedRows

Parameters ​

useTableGroupedRows() takes one config object. Wrap it in a getter or a ref so the sections follow the current rows and the current collapsed set: useTableGroupedRows(() => ({ ... })).

NameTypeDefaultDescription
datareadonly T[]—Required. The flat data to group.
groupBy(item: T) => string—Required. Derive the group key for a row. Rows with the same key share a section.
collapsedGroupsReadonlySet<string>—Required. Set of currently-collapsed group keys.
onToggleGroup(groupKey: string) => void—Required. Called with a group key when its header is toggled.
renderGroupHeader(groupKey: string, count: number, collapsed: boolean) => VNodeChild—Custom renderer for a group header's content, right of the chevron. Defaults to groupKey (count).
getRowKey(item: T) => string—Stable key for a real row. Falls back to a positional key when omitted.
groupOrderreadonly string[]—Explicit group ordering. Groups not listed keep first-seen order after these.

Returns ​

NameTypeDescription
dataComputedRef<T[]>The rows plus one section header per group, in display order. A collapsed group keeps its header and drops its rows.
pluginTablePlugin<T>Makes a section header span the row, skips it for selection and row numbers, and toggles it on click.
idKey(item: T) => stringRow identity for both kinds of row: a section header answers with its group key, a data row with getRowKey or its position.

isTableGroupHeader ​

isTableGroupHeader(item) narrows an item of data to a section header and gives you groupKey and count without a cast. It is the same check the plugin uses.

Section header fields ​

NameTypeDescription
groupKeystringThe key the section was grouped by.
countnumberHow many rows the group holds, whether or not it is open.
idstringStable id of the section header, built from the group key.