logo

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
DaltonDuBuque62single4961
JoshuaDibbert21relationship7444
ShanelleJerde32complicated6358
DinaFritsch33single1416
VickieBailey27relationship7078
KobeLarkin48single9926
SaraiAbernathy40single9940
KasandraKuhic19relationship811
VioletteSchumm45single6482
TaraBotsford35single355
AmeliaHickle29complicated8035
JeremieWeimann63complicated1185
BarneyLangosh64single371
BernitaStark42relationship4580
KiaraWyman56complicated519
MayraHessel62single9641
ErnieLegros49single9097
NobleProhaska54relationship9837
DawsonHettinger56single645
DiegoFlatley22relationship8117
RashawnMcKenzie61complicated697
ElizabethOberbrunner65complicated1058
MackenzieBartell44complicated3690
HeatherLegros64relationship7950
LeilaRoob65complicated2242
EmilyKris44relationship2613
BridieParisian46complicated10056
LudieMorissette46single6135
LelaFranecki21relationship351
AngelHeidenreich46relationship7863