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
AlbertaKertzmann33complicated2378
TrevionLuettgen24relationship413
MakaylaLockman64relationship312
GlennaBoyer32single9694
OllieErdman41single10089
DewayneMayer46relationship8522
OrlandRussel65single4097
JulienTowne45complicated812
ErwinKeebler32complicated5197
BrendaLemke45single2574
HadleyAbshire37single5073
WillaPredovic18single5928
AdrianaBartell24single8832
LillianaDenesik44single5387
WillowMurray34relationship8999
HelenPaucek50relationship631
AliyahGreenholt63relationship3271
JessieArmstrong29relationship6367
IanMcGlynn28single4144
EmiliaLakin54relationship8932
BethelHirthe-Tromp25relationship8259
ChristopherBoyer36single4076
JoannyWeissnat31complicated3730
LlewellynCremin32relationship898
ArdellaSkiles33single4470
AlexzanderLowe22single5692
KeatonHuels55single1976
ElvisWillms63relationship487
CorrineKuhic54complicated2250
GilesAnderson-Waelchi18single8537