addSelectedRows
addSelectedRows keeps track of selected items in the table. Works with sub-rows.
Options
Information:
Options passed into
addSelectedRows.const table = createTable(data, {
select: addSelectedRows({ ... }),
});const table = createTable(data, {
select: addSelectedRows({ ... }),
});initialSelectedDataIds?: Record<string, boolean>
Initial selected row data ids (by row.dataId). Default {}.
linkDataSubRows?: boolean
Link parent/sub-row selection when updating. Default true.
Column Options
Information:
Options passed into column definitions.
const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
select: { ... },
},
}),
]);const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
select: { ... },
},
}),
]);Prop Set
Information:
Extensions to the view model. Subscribe to
.props().{#each $headerRows as headerRow (headerRow.id)}
<Subscribe rowProps={headerRow.props()} let:rowProps>
{rowProps.select}
{#each headerRow.cells as cell (cell.id)}
<Subscribe props={cell.props()} let:props>
{props.select}
</Subscribe>
{/each}
</Subscribe>
{/each}{#each $headerRows as headerRow (headerRow.id)}
<Subscribe rowProps={headerRow.props()} let:rowProps>
{rowProps.select}
{#each headerRow.cells as cell (cell.id)}
<Subscribe props={cell.props()} let:props>
{props.select}
</Subscribe>
{/each}
</Subscribe>
{/each}BodyRow props
selected: booleansomeSubRowsSelected: booleanallSubRowsSelected: boolean
Plugin State
Information:
State provided by
addSelectedRows.const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.select;const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.select;selectedDataIds: Writable<Record<string, boolean>>
allRowsSelected: Writable<boolean>
someRowsSelected: Readable<boolean>
allPageRowsSelected: Writable<boolean>
somePageRowsSelected: Readable<boolean>
getRowState: (row) => SelectedRowsRowState
Examples
| Name (0 users) | Info | ||||||
|---|---|---|---|---|---|---|---|
| First Name | Last Name | Age | Status | Visits | Profile Progress | ||
| ➡️ | Mac | Mohr | 49 | complicated | 98 | 15 | |
| ➡️ | Shana | Wuckert | 39 | complicated | 81 | 84 | |
| ➡️ | Linwood | Grady | 63 | single | 26 | 88 | |
{
"$selectedDataIds": {}
}