Expanding
The ability to expand rows to show additional information.
State
Expanding state is stored on the table using the following shape:
export type ExpandedState = true | Record<string, boolean>
export type ExpandedTableState = {
expanded: ExpandedState
}export type ExpandedState = true | Record<string, boolean>
export type ExpandedTableState = {
expanded: ExpandedState
}Row API
toggleExpanded
toggleExpanded: (expanded?: boolean) => voidtoggleExpanded: (expanded?: boolean) => voidToggles the expanded state (or sets it if expanded is provided) for the row.
getIsExpanded
getIsExpanded: () => booleangetIsExpanded: () => booleanReturns whether the row is expanded.
getCanExpand
getCanExpand: () => booleangetCanExpand: () => booleanReturns whether the row can be expanded.
getToggleExpandedHandler
getToggleExpandedHandler: () => () => voidgetToggleExpandedHandler: () => () => voidReturns a function that can be used to toggle the expanded state of the row. This function can be used to bind to an event handler to a button.
Table Options
manualExpanding
manualExpanding?: booleanmanualExpanding?: booleanEnables manual row expansion. If this is set to true, getExpandedRowModel will not be used to expand rows and you would be expected to perform the expansion in your own data model. This is useful if you are doing server-side expansion.
onExpandedChange
onExpandedChange?: OnChangeFn<ExpandedState>onExpandedChange?: OnChangeFn<ExpandedState>This function is called when the expanded table state changes. If a function is provided, you will be responsible for managing this state on your own. To pass the managed state back to the table, use the tableOptions.state.expanded option.
autoResetExpanded
autoResetExpanded?: booleanautoResetExpanded?: booleanEnable this setting to automatically reset the expanded state of the table when expanding state changes.
enableExpanding
enableExpanding?: booleanenableExpanding?: booleanEnable/disable expanding for all rows.
getExpandedRowModel
getExpandedRowModel?: (table: Table<TData>) => () => RowModel<TData>getExpandedRowModel?: (table: Table<TData>) => () => RowModel<TData>This function is responsible for returning the expanded row model. If this function is not provided, the table will not expand rows. You can use the default exported getExpandedRowModel function to get the expanded row model or implement your own.
getIsRowExpanded
getIsRowExpanded?: (row: Row<TData>) => booleangetIsRowExpanded?: (row: Row<TData>) => booleanIf provided, allows you to override the default behavior of determining whether a row is currently expanded.
getRowCanExpand
getRowCanExpand?: (row: Row<TData>) => booleangetRowCanExpand?: (row: Row<TData>) => booleanIf provided, allows you to override the default behavior of determining whether a row can be expanded.
paginateExpandedRows
paginateExpandedRows?: booleanpaginateExpandedRows?: booleanIf true expanded rows will be paginated along with the rest of the table (which means expanded rows may span multiple pages).
If false expanded rows will not be considered for pagination (which means expanded rows will always render on their parents page. This also means more rows will be rendered than the set page size)
Table API
setExpanded
setExpanded: (updater: Updater<ExpandedState>) => voidsetExpanded: (updater: Updater<ExpandedState>) => voidUpdates the expanded state of the table via an update function or value
toggleAllRowsExpanded
toggleAllRowsExpanded: (expanded?: boolean) => voidtoggleAllRowsExpanded: (expanded?: boolean) => voidToggles the expanded state for all rows. Optionally, provide a value to set the expanded state to.
resetExpanded
resetExpanded: (defaultState?: boolean) => voidresetExpanded: (defaultState?: boolean) => voidReset the expanded state of the table to the initial state. If defaultState is provided, the expanded state will be reset to {}
getCanSomeRowsExpand
getCanSomeRowsExpand: () => booleangetCanSomeRowsExpand: () => booleanReturns whether there are any rows that can be expanded.
getToggleAllRowsExpandedHandler
getToggleAllRowsExpandedHandler: () => (event: unknown) => voidgetToggleAllRowsExpandedHandler: () => (event: unknown) => voidReturns a handler that can be used to toggle the expanded state of all rows. This handler is meant to be used with an input[type=checkbox] element.
getIsSomeRowsExpanded
getIsSomeRowsExpanded: () => booleangetIsSomeRowsExpanded: () => booleanReturns whether there are any rows that are currently expanded.
getIsAllRowsExpanded
getIsAllRowsExpanded: () => booleangetIsAllRowsExpanded: () => booleanReturns whether all rows are currently expanded.
getExpandedDepth
getExpandedDepth: () => numbergetExpandedDepth: () => numberReturns the maximum depth of the expanded rows.
getExpandedRowModel
getExpandedRowModel: () => RowModel<TData>getExpandedRowModel: () => RowModel<TData>Returns the row model after expansion has been applied.
getPreExpandedRowModel
getPreExpandedRowModel: () => RowModel<TData>getPreExpandedRowModel: () => RowModel<TData>Returns the row model before expansion has been applied.
Credits
- Expanding - TanStack Table
v8Docs