alexbruf/elm-table/1.0.0

Table.FilterFn

Built-in filter functions, ported from column-filtering/filterFns.ts.

A FilterFn is a comparison between a cell value and a filter value plus three helpers that TanStack attaches to every filter fn:

  • resolveFilterValue normalises the filter value once per filter before any row is tested (the table does this, not filter).
  • resolveDataValue normalises the cell value before comparison (filter does this).
  • autoRemove says when a filter value is blank enough that the filter should be dropped from state.
  • meta, when the filter fn has one, produces the value the filtered row model records for the row under Table.rowColumnFiltersMeta. It is TanStack's addMeta callback turned into a return value.

Type

A filter comparison with its resolvers.

Basic

Strict equality.

Loose equality ("1" == 1).

Strings

Case-insensitive substring match.

Case-sensitive substring match.

Case-insensitive string equality.

Case-sensitive string equality.

Case-insensitive prefix match.

Case-insensitive suffix match.

Blank

Keeps blank cells. The filter value is only an on/off flag.

Keeps non-blank cells. The filter value is only an on/off flag.

Numbers

Numeric when both sides parse as numbers, string comparison otherwise.

Ranges

Exclusive range; the filter value is List [ min, max ].

Inclusive range; the filter value is List [ min, max ].

Inclusive numeric range; only Number cells can match.

Inclusive date range on Date cells (or timestamps, or YYYY-MM-DD strings).

Arrays

Scalar cell equals at least one of the filter values.

List or String cell includes at least one filter value.

List cell includes every filter value.

List cell includes at least one filter value.

Building your own

custom : (Value -> Value -> Bool) -> FilterFn

Build a filter fn from a comparison. Resolvers default to identity and autoRemove defaults to removing Null and the empty string.

Replace the filter-value normaliser.

Replace the cell-value normaliser.

Replace the auto-remove predicate.

withMeta : (Value -> Value -> Maybe Value) -> FilterFn -> FilterFn

Give a filter fn the meta the filtered row model records for every row it tests, TanStack's addMeta callback.

The function is handed the already resolved cell value and the already resolved filter value, the same two values filter compares, and Nothing records nothing for that row. This is how the fuzzy-filter example stores its match rank and then sorts by it.

Applying

filter : FilterFn -> Value -> Value -> Bool

Test a raw cell value against an already resolved filter value. The cell value is passed through resolveDataValue first; the filter value is not (resolve it once with resolveFilterValue).

Normalise a filter value.

Normalise a cell value.

Should this filter value cause the filter to be dropped?

meta : FilterFn -> Maybe (Value -> Value -> Maybe Value)

The filter fn's meta producer, when withMeta gave it one. Nothing is the common case and lets the filtered row model skip the work entirely.

Dates

toDateTimestamp from filterFns.ts: a Date gives its milliseconds, a Number passes through, and everything else that is not a parseable date string gives NaN, which never falls inside a range.

Elm has no new Date(string), so the string form is limited to ISO 8601 YYYY-MM-DD, optionally followed by THH:MM, THH:MM:SS and a Z.