addColumnFilters

addColumnFilters filters table rows by specific column values.

Options

Information:
Options passed into addColumnFilters.
const table = createTable(data, {
  colFilter: addColumnFilters({ ... }),
});
const table = createTable(data, {
  colFilter: addColumnFilters({ ... }),
});

serverSide?: boolean

If true, filtering will not change $rows. Control filtering by updating $data and use plugin state to drive your fetch.

Defaults to false.

Column Options

Information:
Options passed into column definitions.
const columns = table.createColumns([
  table.column({
    header: 'Name',
    accessor: 'name',
    plugins: {
      colFilter: { ... },
    },
  }),
]);
const columns = table.createColumns([
  table.column({
    header: 'Name',
    accessor: 'name',
    plugins: {
      colFilter: { ... },
    },
  }),
]);

fn: ({ filterValue, value }) => boolean

Defines filter behavior for the column. Return true to keep the row.

render?: (renderProps) => RenderConfig

Renders a control on HeaderCell->props.[pluginName].render. renderProps extends TableState and includes:

  • id: string
  • filterValue: Writable<any>
  • values: Readable<any[]>
  • preFilteredValues: Readable<any[]>
  • preFilteredRows: Readable<BodyRow[]>

initialFilterValue?: any

Initial filter value.

Prop Set

Information:
Extensions to the view model. Subscribe to .props() on table components.
{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.colFilter}
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.colFilter}
      </Subscribe>
    {/each}
  </Subscribe>
{/each}
{#each $headerRows as headerRow (headerRow.id)}
  <Subscribe rowProps={headerRow.props()} let:rowProps>
    {rowProps.colFilter}
    {#each headerRow.cells as cell (cell.id)}
      <Subscribe props={cell.props()} let:props>
        {props.colFilter}
      </Subscribe>
    {/each}
  </Subscribe>
{/each}

Plugin State

Information:
State provided by addColumnFilters.
const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.colFilter;
const { headerRows, rows, pluginStates } = table.createViewModel(columns);
const { ... } = pluginStates.colFilter;

preFilteredRows: Readable<BodyRow<Item>[]>

Rows before filtering.

filterValues: Writable<Record<Id, FilterValue>>

Active filter values by column id.

Examples

$filterValues = {}
Name Info
First Name
Last Name
Age
to
Status
Visits
Profile Progress
ClaudineMoore54relationship5229
JanetGoodwin37complicated2963
DwayneConsidine25relationship9796
MaryMayert18single5264
SashaKovacek65complicated4082
AlexandreFriesen64complicated6382
TremaineBotsford35single355
GeorgianaHerman48single4958
RossHoppe42relationship9737
JaceKing56complicated257
ArchProsacco33single3693
GarnetOkuneva60single9777
OswaldoBoehm29single2236
RachaelFlatley22relationship8117
KelvinWintheiser45complicated3083
KareemFlatley19single5436
LurlineSchamberger-Kunze28single6175
GustaveHickle40relationship5426
ErnaZieme44single5564
KingMitchell32complicated247
AmieMcLaughlin55single6316
LloydNitzsche65relationship7718
OdieSchulist27relationship1541
NilsMiller64complicated3850
RansomKessler24complicated2084
LedaRatke30single055
LeopoldGreenholt38complicated5799
IsidroSanford26single1321
EugeniaSchroeder39relationship452
SamanthaCole35single9243