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
➡️MaxwellKuphal36complicated4182
➡️CarolBeatty58complicated82100
➡️NorwoodBernhard21relationship5599
➡️KrystelGreenholt53relationship242
➡️GertrudeHansen56complicated9167
➡️HaroldBarrows59complicated117
➡️SheilaRussel24relationship8276
➡️DiegoKoepp53complicated9463
➡️MarionMacGyver29complicated1283
➡️MiltonLeannon52relationship3751

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
LeilaMueller27complicated1769
MaeganParker57relationship9940
QuintenWolff32single6884
MozelleMcDermott26relationship3789
ChandlerReinger22single3995
DeangeloSchuppe18single1522
OrieBaumbach44complicated2164
SierraHills33relationship9688
GertrudeBarton29complicated9398
ModestoRussel64relationship5833
HeathStiedemann40complicated3375
DavonteKertzmann44relationship1045
AnnabelBalistreri60complicated4862
BobbyBailey42single8041
LiaPredovic-Kihn24complicated2949
OsbaldoD'Amore35single2282
KayHayes62relationship965
AndyGorczany55single5215
AudraKemmer62relationship9381
BuckDavis65single8922
ForestStoltenberg50relationship9247
AltaTreutel28relationship2279
DallasCormier42single9880
AngieSchimmel59relationship6016
ImaHessel28single2751
VernerReynolds50complicated9270
LoganCarroll60single8294
RaymondBorer56relationship5170
ShirleyToy38relationship7367
SydneyTrantow37complicated3236