logo

addExpandedRows

addExpandedRows expands and collapses sub-rows of rows. Sub-rows are defined by plugins such as addSubRows or addGroupBy.

Options

Information:
Options passed into addExpandedRows.
const table = createTable(data, {
  expand: addExpandedRows({ ... }),
});
const table = createTable(data, {
  expand: addExpandedRows({ ... }),
});

initialExpandedIds?: Record<string, boolean>

Initial expanded row ids as an object mapping rowId => boolean. Nested sub-rows use {parentId}>{id}.

Column Options

Information:
Options passed into column definitions.
const columns = table.createColumns([
  table.column({
    header: 'Name',
    accessor: 'name',
    plugins: {
      expand: { ... },
    },
  }),
]);
const columns = table.createColumns([
  table.column({
    header: 'Name',
    accessor: 'name',
    plugins: {
      expand: { ... },
    },
  }),
]);

Prop Set

Information:
Extensions to the view model. Subscribe to .props().
{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.expand}
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.expand}
      </Subscribe>
    {/each}
  </Subscribe>
{/each}
{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.expand}
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.expand}
      </Subscribe>
    {/each}
  </Subscribe>
{/each}

Plugin State

Information:
State provided by addExpandedRows.
const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.expand;
const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.expand;

expandedIds: Writable<Record<string, boolean>>

Active expanded rows mapping.

getRowState: (row) => ExpandedRowsRowState

Returns state for a given BodyRow with:

  • isExpanded: Writable<boolean>
  • canExpand: Readable<boolean>
  • isAllSubRowsExpanded: Readable<boolean>

Examples

Simple row expanding

Name (0 users)Info
First NameLast NameAgeStatusVisitsProfile Progress
➡️SisterSchuster20complicated1060
➡️HeavenSpinka23complicated2921
➡️LuisaSchmitt37relationship250
➡️JettLynch23complicated3593
➡️WilfredJohns41single2038
➡️FelixBraun52complicated5066
➡️MarcelleQuitzon29single9533
➡️DanykaBayer65single4564
➡️ErynSchimmel58relationship9599
➡️AngelicaNitzsche63relationship2251

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
ArdenKessler52complicated9854
AntoniettaKutch50relationship8138
EdwardEffertz39complicated942
ValentinaLowe61single1352
MarcelleDoyle41complicated3748
RodrickHaley45complicated2745
MadysonKoelpin52relationship4191
NaomiKautzer48relationship5241
AudreyLeffler51relationship9668
ElroyFeil64complicated9585
RonHagenes40relationship7449
EverettGutkowski25single4145
PeytonKoelpin55single8968
TreyTerry31single4880
CaitlynBernhard35complicated8243
MonserratRowe18relationship4246
KareemShields63complicated1223
BrennanMarvin26relationship7986
KaceyWolf31single1788
ClintReichel58single1667
KatherynBarton31relationship814
FrancesCormier19complicated5270
BrianMcLaughlin63relationship10024
RickeyKoch55single8761
AlbertaGottlieb23single913
AntonetteJohnson26relationship5254
MyraDickinson35single3820
RhiannaHills29complicated4527
TheresaO'Hara46single756
TysonGreen50relationship7166