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
➡️ChynaHudson26single9893
➡️WymanKiehn64single6059
➡️LedaRyan48relationship4844
➡️DaleWard30relationship917
➡️AricSchuppe50complicated815
➡️TamiaMurphy47complicated5668
➡️FelicitaUpton62single4466
➡️BreanneBartoletti31complicated1875
➡️TressieSchamberger57single5171
➡️TavaresOkuneva52complicated871

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
AugustusPagac63complicated949
MyrticeRodriguez55complicated458
BettySchulist55complicated1287
VidalCremin25relationship7850
BertFunk53single3164
PercyStanton27single1191
KristyRutherford55complicated931
HillardKuhn51single9720
EffieWeissnat55complicated9074
TysonSchmitt53relationship8485
TrevaKunze27relationship1019
DasiaBotsford43complicated707
SammyEffertz61complicated4330
JoannyLangosh21relationship4518
ManuelaMcGlynn21relationship4167
WillyTremblay22complicated6595
BretConnelly23complicated9285
DylanKris65single7966
NikkiFeil58complicated4814
DestinHerman39complicated7676
CiceroKertzmann48complicated77
SantosGlover26complicated737
EwellKovacek19single2145
AlexHartmann20complicated5865
SkyeHerzog44complicated187
MadisenHahn22complicated1239
AnabelleSmitham33single9111
KamilleCormier31complicated19100
FannieKrajcik32single8123
JewellWisoky26single1663