Skip to content
Source
Sign inSign up
TanStack/table

`filterFn.autoRemove` ignored for empty strings #6101

Closedaa-ndrej(GitHub profile, opens in a new tab) opened this issue 0 comments

TanStack Table version

v8.21.3

Framework/Library version

Vue 3.5.21

Describe the bug and the steps to reproduce it

I have the following column:

columnHelper.accessor('foo', {
  filterFn: (() => {
    const filterFn = (row, columnId, filterValue) => {
      return filterValue === row.getValue(columnId)
    }
    filterFn.autoRemove = val => val === undefined
    return filterFn
  })(),
})

I use filterFn.autoRemove = val => val === undefined in order to only remove the filter if the value is undefined. The provided autoRemove function is however ignored if I do column.setFilterValue('') and the filter array remains empty.

Here is the code causing this: https://github.com/TanStack/table/blob/02c203afed5865cfec0aa614de9f2861645d6ff9/packages/table-core/src/features/ColumnFiltering.ts#L423-L427

I would expect the function I provide to take precedence, because otherwise there is no way to filter for empty strings. All build in filter functions have code like testFalsey(val) so a change would not impact the current behavior of the build in functions.

I would even go as for and remove the check for typeof value === 'undefined' if a custom function is provided.

No response

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Yes, I think I know how to fix it and will discuss it in the comments of this issue

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. KevinVandy closed this

Sign in to join this conversation.