title | description | sidebar_title |
---|---|---|
addColumnFilters |
Filter table rows by column values |
addColumnFilters |
addColumnFilters
filters table rows by specific column values.
:::callout
Options passed into addColumnFilters
.
:::
const table = createTable(data, {
colFilter: addColumnFilters({ ... }),
});
Nothing here so far.
:::callout Options passed into column definitions. :::
const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
colFilter: { ... },
},
}),
]);
Defines the filter behavior for the column.
Receives filterValue
and the column cell value
, and returns true
if the cell should be visible.
Defines the component to render on HeaderCell->props.[pluginName].render
.
renderProps
extends TableState
and includes additional properties.
The id of the column.
A Writable
store with the current filter value.
A Readable
store with the filtered values on the column.
A Readable
store with the pre-filtered values on the column.
A Readable
store with the pre-filtered rows on the table.
Defines the initial filter value for the column.
Defaults to undefined
.
:::callout Extensions to the view model.
Subscribe to .props()
on the respective table components.
:::
{#each $headerRows as headerRow (headerRow.id)}
<Subscribe rowProps={headerRow.props()} let:rowProps>
{rowProps.colFilter} <!-- HeaderRow props -->
{#each headerRow.cells as cell (cell.id)}
<Subscribe props={cell.props()} let:props>
{props.colFilter} <!-- HeaderCell props -->
</Subscribe>
{/each}
</Subscribe>
{/each}
Possibly undefined
if no filter is configured on the column represented by the header cell.
The render
component defined in the column options of the data column represented by the header cell.
:::callout
State provided by addColumnFilters
.
:::
const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.colFilter;
The view model rows before filtering.
The active filter values. A record of column id to filter value.
:::example
<script> import SimpleFilteringDemo from './SimpleFilteringDemo.svelte'; </script> :::