table icon indicating copy to clipboard operation
table copied to clipboard

Cell's filterFn never gets called

Open SpadarShut opened this issue 2 years ago • 13 comments

Describe the bug

The filterFn prop of a cell definition never gets called. My initial problem was that the filterFn's resolveFilterValue was never called, but in fact filterFn is just ignored.

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/stupefied-water-3kcw7h?embed=1&file=%2Fsrc%2Fmain.tsx%3A52%2C18

Steps to reproduce

1 Create a basic table with a filterFn prop on a cell 2 Optionally add globalFilter 3 try to search

Expected behavior

As a user I expect filterFn to be called, but returning false from the fn of plain console.log/alert never gets executed.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS

react-table version

8.9.3

TypeScript version

5.1.3

Additional context

No response

Terms & Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] 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.

SpadarShut avatar Jun 29 '23 13:06 SpadarShut

I am going to take a look at this and try to publish a fix. Can you assign it to me?

arnaugomez avatar Jul 02 '23 21:07 arnaugomez

After looking at the code and your example, I have found that it may not be a bug. The filter function only gets called if there is a columnFilters property in the state object of the table, and this property contains a value that corresponds to the filter value of the column.

Check out the official filters example: https://codesandbox.io/p/sandbox/github/tanstack/table/tree/main/examples/react/filters?embed=1&file=%2Fsrc%2Fmain.tsx%3A352%2C20-352%2C29

Should we close the issue or make changes to the documentation to explain it more clearly?

arnaugomez avatar Jul 04 '23 09:07 arnaugomez

@arnaugomez thanks for looking into the issue! If this is the intended behaviour, this should be documented I think. And also, what is then the intended way to transform cell value for (global) filters?

SpadarShut avatar Jul 04 '23 09:07 SpadarShut

@SpadarShut as I see it, the filter function filterFn is, along with the filters state, the correct way to filter the data.

I plan to issue a PR tomorrow with a proposal to make the documentation clearer on this subject. Thanks for the suggestion 😄

arnaugomez avatar Jul 04 '23 17:07 arnaugomez

cant find the PR.

Can the global filter use a custom filterFn for a specific column? It doesn't seem like it. Do I need to define one global filter fn like the fuzzyFilter example, and put a if (columnId === 'my special column") in it?

laduke avatar Dec 08 '23 22:12 laduke

And also, what is then the intended way to transform cell value for (global) filters?

Do we have a solution to this?

sarthakgupta072 avatar Dec 12 '23 08:12 sarthakgupta072

Any update on this? The documentation for global filters demonstrates using a column's filterFn for global filtering, but when using an inline function for filterFn, the function never gets called.

HeathHopkins avatar May 10 '24 01:05 HeathHopkins

for global filtering, the table uses the globalFilterFn

KevinVandy avatar May 10 '24 01:05 KevinVandy

@KevinVandy, thanks!

HeathHopkins avatar May 10 '24 13:05 HeathHopkins