Repository navigation
Description
Describe the bug
If the first row of a table has an undefined value in a column, the global filter won't work on that column, regardless of valid values in subsequent rows.
Take for example:
| ID | Other |
|---|---|
| test | |
| hello | test |
| world | test |
Searching for hello with the global filter fails, even though it's clearly there. As soon as the order of the rows within the data is reversed, the global filters begins to work again.
Your minimal, reproducible example
Steps to reproduce
Create a table where the first row of data has an undefined value. Subsequent rows should have string values. Upon using the global filter to search for an existing value, nothing is shown.
Expected behavior
Global filter should work, regardless of row order.
How often does this bug happen?
Every time
Screenshots or Videos
0247.mp4
Platform
- OS: Windows
- Browser: Firefox
react-table version
8.8.2
TypeScript version
No response
Additional context
This may be due to the default getColumnCanGlobalFilter implementation:
table/packages/table-core/src/features/Filters.ts
Lines 190 to 196 in 134414e
| getColumnCanGlobalFilter: column => { | |
| const value = table | |
| .getCoreRowModel() | |
| .flatRows[0]?._getAllCellsByColumnId() | |
| [column.id]?.getValue() | |
| return typeof value === 'string' || typeof value === 'number' |
It seems to check the first row's values to determine if certain columns can be globally filtered.
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.
Activity
codebycarlos commentedon Mar 30, 2023
Potentially related to #4711, #4673, #4594.
codebycarlos commentedon Mar 30, 2023
I'm not familiar with the motivation behind getColumnCanGlobalFilter. But the idea of determining column filterability based on the first row will undoubtedly be a footgun for many people using TanStack/table. Perhaps it's best that the default implementation always returns true?
michasng commentedon Mar 3, 2025
This was certainly a footgun for me, because my local testing data didn't include
undefined.Always returning
trueis equally wrong by not filtering at all (as opposed to filtering out everything).I'm assuming this can only be solved by making the
autoFilterFndepend on each filtered row. It should not depend on some random row, like the first one.