Skip to content

Expanding Rows and Detail Panels

Put the children on each row in a subRows array and enable expanding:

const data = [
{ name: 'Ada', subRows: [{ name: 'Grace' }, { name: 'Linus' }] },
];
<ShadcnSvelteTable options={{ columns, data, enableExpanding: true }} />

Use getSubRows if your children live under another key. Start expanded with initialState: { expanded: true }.

OptionWhat it does
enableExpandAllShow the expand all button in the header.
positionExpandColumn'first' (default) or 'last'.
paginateExpandedRowsSet false to keep a parent and its children on one page.
filterFromLeafRowsFilter on the children and keep their parents.
maxLeafRowFilterDepthHow deep filtering looks into sub rows.
expandButtonPropsProps for each expand button.

A detail panel is an extra row under the clicked row. Give the detailPanel snippet; the expand column appears on its own.

{#snippet detailPanel({ row })}
<p>{row.original.biography}</p>
{/snippet}
<ShadcnSvelteTable options={{ columns, data, detailPanel }} />

Render nothing for rows that have no details, or hide just their button with expandButtonProps:

expandButtonProps: ({ row }) => ({
style: row.original.biography ? '' : 'visibility: hidden',
}),

To open only one panel at a time, manage expanded yourself and keep the last toggled row id.

See the Detail panel example and the Expanding tree example.