Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row selection not updating after adding filters #317

Closed
1 task done
vuckookv3 opened this issue Apr 21, 2024 · 4 comments
Closed
1 task done

Row selection not updating after adding filters #317

vuckookv3 opened this issue Apr 21, 2024 · 4 comments
Labels
bug Something isn't working V2 Issue with MRT V2

Comments

@vuckookv3
Copy link

mantine-react-table version

^2.0.0-beta.1

react & react-dom versions

18.2.0

Describe the bug and the steps to reproduce it

  1. Select all rows (it should say 10 of 12 rows selected)
  2. Export Selected Rows (all 10 rows exported, all good)
  3. Add any filter (for example, search City and write "ea")
  4. It should say 4 of 4 rows selected
  5. Export Selected Rows (it exports all 10 again)

Minimal, Reproducible Example - (Optional, but Recommended)

https://codesandbox.io/p/devbox/github/KevinVandy/mantine-react-table/tree/v2/apps/mantine-react-table-docs/examples/export-to-pdf/sandbox

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.
@vuckookv3
Copy link
Author

I should also mention to just change columnFilterDisplayMode: 'popover', to subheader or just comment out that line, to get filters to work (maybe that's another bug with popover?)

@alessandrojcm alessandrojcm added bug Something isn't working V2 Issue with MRT V2 labels Apr 25, 2024
@alessandrojcm
Copy link
Collaborator

alessandrojcm commented Apr 29, 2024

Hi there, so I've been playing around with this. And although I can reproduce this behavior with both popover and subheader I do not believe this is a bug. The reasons is that filtering the rows does not alter the selection even in TanStack Table itself, however, to achieve the behaviour you want, you can use getFilteredSelectedRowModel instead. This comes directly from TanStack so the typings won't match MRT_TableRow.

@vuckookv3
Copy link
Author

vuckookv3 commented Apr 29, 2024

Hey,

what I did in the end, was keeping columnFilters in a state.
And then I just resetted the selections every time filters change, like so:

useEffect(() => { table.resetRowSelection(); }, [columnFilters]);

So I am forcing the user to click again on "Select All" checkbox, so that I can get a new selection.

@alessandrojcm
Copy link
Collaborator

Great that you solved it! I think you should try with the method I mentioned above though, it might allow you to implement the same functionality without the extra useEffect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working V2 Issue with MRT V2
Projects
None yet
Development

No branches or pull requests

2 participants