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
➡️RomanMertz43complicated4233
➡️ReubenKling30single6258
➡️JaimeRuecker53single4213
➡️ShaynaGrady42single4367
➡️ElmoreEbert40relationship2094
➡️ArianeProsacco64single8611
➡️DelbertReinger36complicated4570
➡️NicholeKemmer41single2098
➡️RandolphFay64complicated9551
➡️MartinMedhurst58relationship2644

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
IbrahimLind-Kuvalis21single2750
ArthurEffertz39complicated942
JuliusLedner54relationship6747
JuliaRunte33complicated5727
FritzJerde61complicated1874
JuanitaBosco52single5270
EmilioWintheiser63single8547
JosephineCollins34relationship3230
PatsyKoelpin55single8968
ShaunSchinner52relationship1466
HilarioSchuster54complicated042
LucyChamplin29relationship6613
RaymondLemke56relationship9827
ClintSporer26complicated6781
EricaAdams35relationship615
HesterMcLaughlin63relationship10024
JadonMonahan59relationship227
AlexanderHessel38complicated1852
CarolanneHodkiewicz27relationship9283
JoanneWalker36single6560
TysonPacocha52single6614
LeeSchuppe-Nienow54relationship1831
StevenBraun50relationship8263
RonnieLangworth48complicated2685
BabyRomaguera44relationship4690
AlonzoTrantow46relationship3499
GabeHansen60relationship6533
GusTromp25single7813
TomLedner22relationship1015
TraciCarter28complicated7794