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
➡️RickyMertz43complicated4233
➡️RobertoKling30single6258
➡️HeleneRuecker53single4213
➡️SharonGrady42single4367
➡️EmeraldEbert40relationship2094
➡️AnjaliProsacco64single8611
➡️DeanReinger36complicated4570
➡️MyrticeKemmer41single2098
➡️PasqualeFay64complicated9551
➡️MajorMedhurst58relationship2644

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
JanaeLind-Kuvalis21single2750
ArthurEffertz39complicated942
JonasLedner54relationship6747
JosefinaRunte33complicated5727
GillianJerde61complicated1874
KayceeBosco52single5270
ElliotWintheiser63single8547
JessycaCollins34relationship3230
NonaKoelpin55single8968
ShermanSchinner52relationship1466
IvySchuster54complicated042
LisaChamplin29relationship6613
PhillipLemke56relationship9827
ClaudieSporer26complicated6781
ElenaAdams35relationship615
GuyMcLaughlin63relationship10024
JessieMonahan59relationship227
AliHessel38complicated1852
CandidaHodkiewicz27relationship9283
JazminWalker36single6560
TryciaPacocha52single6614
KentSchuppe-Nienow54relationship1831
SylvanBraun50relationship8263
RoderickLangworth48complicated2685
BradlyRomaguera44relationship4690
AllanTrantow46relationship3499
GinaHansen60relationship6533
JalynTromp25single7813
TrevionLedner22relationship1015
UnaCarter28complicated7794