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
➡️RyannSchuster52single9920
➡️YasminePollich50relationship5225
➡️VickieKshlerin61complicated8478
➡️VerlieWuckert34complicated9146
➡️HayleyAbernathy47relationship3057
➡️AlenaBoehm61single1245
➡️BartholomeVonRueden62complicated120
➡️CamdenHauck26complicated282
➡️FredKeeling48relationship8515
➡️TyshawnHessel35complicated7336

Simple grouping by column

{
  "$groupByIds": []
}
Name (0 users) Info
First Name Last Name Age Status Visits Profile Progress
JessyHagenes34complicated477
EzraCremin31relationship2049
SimoneKilback51relationship6310
WilhelmineLittle-Morar26complicated6395
ThaliaBahringer18single8887
JoannieSchowalter30single4878
MekhiBauch-Bayer64relationship9590
BettyeDaugherty46relationship895
CarolinaWeissnat-Hegmann35relationship2751
FrederickWunsch-Hagenes33relationship6393
DaniellaJohnson18complicated4333
DorianBalistreri42relationship5363
TysonQuigley18complicated474
MontanaAnderson64single1939
JoanaHarvey49single4512
DelaneyGraham53complicated838
VincenzoRenner19single5751
SashaO'Hara25single9163
JustynWunsch21single4196
CarolynJacobson25complicated9872
ArneOrtiz36relationship9116
LouisaHintz50complicated3531
JennyferKoss18single2888
RaphaelleWill39single3718
TitoMoore41relationship419
ChristineWhite59complicated1924
JoannieUllrich34complicated645
VincenzaKiehn41single2292
LesleyBrekke29complicated3657
NathanaelHeller60single2875