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
CoraMoore54relationship5229
IleneGoodwin37complicated2963
EdgarConsidine25relationship9796
MeredithMayert18single5264
SaraiKovacek65complicated4082
AlfredoFriesen64complicated6382
TiffanyBotsford35single355
HazelHerman48single4958
RussellHoppe42relationship9737
JeffKing56complicated257
AmiyaProsacco33single3693
ErnieOkuneva60single9777
OceaneBoehm29single2236
RitaFlatley22relationship8117
LamarWintheiser45complicated3083
KyleFlatley19single5436
MamieSchamberger-Kunze28single6175
HoraceHickle40relationship5426
FlorenceZieme44single5564
LelandMitchell32complicated247
AntoniaMcLaughlin55single6316
ManuelNitzsche65relationship7718
NellieSchulist27relationship1541
PatMiller64complicated3850
RickyKessler24complicated2084
KipRatke30single055
LyleGreenholt38complicated5799
JaquelinSanford26single1321
GenevieveSchroeder39relationship452
ShawnaCole35single9243