Show/hide filter triggers onColumnFiltersChange for backend pagination
jerlam06 opened this issue · 4 comments
material-react-table version
2.12.1
react & react-dom versions
18.2
Describe the bug and the steps to reproduce it
When implementing backend pagination, the show/hide filter buttons triggers onColumnFiltersChange on EVERY click when specifying filterFn: 'between', even when the table just loaded and there is no filter applied at all. It is very annoying because it triggers a call to my pagination backend API.
Minimal, Reproducible Example - (Optional, but Recommended)
Optional
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
No, because I do not know how
Terms
- I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
This is most likely a problem with your fetching logic. And since you did not provide a repro, I'm just going to close this.
@KevinVandy I cannot reproduce it because MRT doesnt seem to work in Stackblitz or Codesandbox:
- https://codesandbox.io/p/devbox/github/KevinVandy/material-react-table/tree/v2/apps/material-react-table-docs/examples/remote/sandbox?file=%2Fsrc%2Fmain.tsx%3A10%2C1
- https://stackblitz.com/github/KevinVandy/material-react-table/tree/v2/apps/material-react-table-docs/examples/remote/sandbox?file=src%2FTS.tsx
PS: I am 100% positive it is not coming from my implementation, it only does that with min/max. It is basically adding the filter for min/max with undefined values:
[ { "id": "adjustedPrice", "value": [ undefined, undefined ] }, { "id": "recommendedPrice", "value": [ undefined, undefined ] }, { "id": "currentPrice", "value": [ undefined, undefined ] }, { "id": "brand", "value": [ "ACTION" ] } ]
If the filter value is empty for both min and max, it should be removed from the filter state, right ?
@jerlam06 It works perfectly fine. You'll just have to mock your own API returns in a sandbox. To make a reproduction, you just have to prove that some state is causing a re-render of some other unrelated state that it is not supposed to.
@KevinVandy Ok thanks. I could reproduce it there => https://stackblitz.com/edit/github-8arb9x?file=src%2FTS.tsx
Open the dev console and trigger show/hide filters, show filters triggers a filter state change for no reason. Plus, the min/max filters remain in the filter state even when empty, this is not consistent I believe.
Thanks in advance, and very good job with the v2, it is amazing :)