Skip to content

Global Filter Fails When First Row Value is Undefined #4783

Description

@codebycarlos

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

https://codesandbox.io/p/sandbox/adoring-sid-ro5tmg?file=%2Fsrc%2Fmain.tsx&selection=%5B%7B%22endColumn%22%3A26%2C%22endLineNumber%22%3A56%2C%22startColumn%22%3A26%2C%22startLineNumber%22%3A56%7D%5D

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions