addTableFilter
addTableFilter filters table rows on data that may be in any column.
Options
Information:
Options passed into
addTableFilter.const table = createTable(data, {
filter: addTableFilter({ ... }),
});const table = createTable(data, {
filter: addTableFilter({ ... }),
});fn?: ({ filterValue, value }) => boolean
Custom filter. filterValue is a string; value is serialized to string by default.
initialFilterValue?: string
Default ''.
includeHiddenColumns?: boolean
Whether hidden columns are included. Default false.
serverSide?: boolean
If true, use server-side filtering by updating $data.
Column Options
Information:
Options passed into column definitions.
const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
filter: { ... },
},
}),
]);const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
filter: { ... },
},
}),
]);exclude?: boolean
Exclude the column from search. Default false.
getFilterValue?: (value) => string
Map a cell value to a filterable string. Default serializes value.
Prop Set
Information:
Extensions to the view model. Subscribe to
.props().{#each $headerRows as headerRow (headerRow.id)}
<Subscribe rowProps={headerRow.props()} let:rowProps>
{rowProps.filter}
{#each headerRow.cells as cell (cell.id)}
<Subscribe props={cell.props()} let:props>
{props.filter}
</Subscribe>
{/each}
</Subscribe>
{/each}{#each $headerRows as headerRow (headerRow.id)}
<Subscribe rowProps={headerRow.props()} let:rowProps>
{rowProps.filter}
{#each headerRow.cells as cell (cell.id)}
<Subscribe props={cell.props()} let:props>
{props.filter}
</Subscribe>
{/each}
</Subscribe>
{/each}BodyCell
matches: boolean — whether the cell matches the current filter value.
Plugin State
Information:
State provided by
addTableFilter.const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.filter;const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.filter;preFilteredRows: Readable<BodyRow<Item>[]>
filterValue: Writable<string>
Examples
$filterValue =
| Name | Info | ||||
|---|---|---|---|---|---|
| First Name | Last Name | Age | Status | Visits | Profile Progress |
| Autumn | Bednar | 28 | single | 41 | 99 |
| Misty | Marquardt | 53 | complicated | 69 | 42 |
| Skye | Schmidt | 55 | relationship | 40 | 10 |
| Erin | Weissnat | 42 | single | 99 | 71 |
| Dameon | Macejkovic | 33 | relationship | 90 | 56 |
| Jorge | Brakus | 60 | single | 30 | 25 |
| Jonathan | Spencer | 36 | relationship | 89 | 21 |
| Andre | Wunsch | 56 | relationship | 62 | 35 |
| Stephanie | Ebert | 61 | relationship | 32 | 47 |
| Clotilde | Hintz | 63 | single | 81 | 0 |
| Kaitlyn | Prosacco | 24 | single | 50 | 54 |
| Kristy | Towne | 56 | single | 18 | 83 |
| Allene | VonRueden | 41 | relationship | 4 | 48 |
| Alisha | Bernier | 21 | relationship | 22 | 97 |
| Darryl | Lueilwitz | 31 | relationship | 83 | 38 |
| Wilbert | Mante | 50 | complicated | 29 | 34 |
| Francis | Kozey | 53 | relationship | 49 | 8 |
| Abel | Bechtelar | 33 | single | 82 | 71 |
| Cristal | Toy | 20 | relationship | 85 | 12 |
| Lila | Kihn | 54 | complicated | 76 | 9 |
| Jamal | Upton | 53 | complicated | 73 | 73 |
| Aiyana | Ebert | 59 | complicated | 94 | 57 |
| Cheyanne | Toy | 60 | relationship | 93 | 59 |
| Demarco | Marvin | 58 | relationship | 80 | 25 |
| Gwen | Sanford | 20 | single | 46 | 13 |
| Dino | Barton | 28 | relationship | 58 | 76 |
| Kailyn | Rau | 59 | single | 65 | 95 |
| Fabiola | Kuvalis | 40 | single | 49 | 1 |
| Carson | Champlin | 27 | single | 10 | 71 |
| Laury | Herzog | 37 | single | 15 | 0 |