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
➡️RonMertz43complicated4233
➡️RebekahKling30single6258
➡️IrmaRuecker53single4213
➡️ShannaGrady42single4367
➡️ElodyEbert40relationship2094
➡️AraceliProsacco64single8611
➡️DavidReinger36complicated4570
➡️NayeliKemmer41single2098
➡️RandyFay64complicated9551
➡️MathewMedhurst58relationship2644

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
IgnatiusLind-Kuvalis21single2750
ArthurEffertz39complicated942
JulioLedner54relationship6747
JulieRunte33complicated5727
GabeJerde61complicated1874
JuddBosco52single5270
ElijahWintheiser63single8547
JoyCollins34relationship3230
PattiKoelpin55single8968
ShawnSchinner52relationship1466
HillarySchuster54complicated042
LydiaChamplin29relationship6613
RaymondLemke56relationship9827
CletusSporer26complicated6781
ElviraAdams35relationship615
HildegardMcLaughlin63relationship10024
JadeMonahan59relationship227
AlejandrinHessel38complicated1852
CarletonHodkiewicz27relationship9283
JoanneWalker36single6560
UbaldoPacocha52single6614
LeoSchuppe-Nienow54relationship1831
StevenBraun50relationship8263
RooseveltLangworth48complicated2685
AugustusRomaguera44relationship4690
AllenTrantow46relationship3499
GabriellaHansen60relationship6533
HaileeTromp25single7813
TomLedner22relationship1015
TraceyCarter28complicated7794