-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Pagination and Row Selection #4781
Comments
I am having the same issue here |
related issue I'm having with fully controlled state: #4812 |
I also have this issue. |
Have same issue with server side pagination. When I move to another page it shows same index of the rows are selected as well |
Hi, I am trying to implement row selection (a global all row select) using server-side pagination. It seems to be the same use case as you. After trying different methods and comparing to the CodesandBox provided, i think there is no bug here and the behaviour is totally fine. We do need getRowId: (row) => {
return row.id
}, that you now rely on the In the example provided on the docs and in your sandbox, the option From this conclusion, i believe there is 2 solutions:
<div className='flex-1 text-sm text-muted-foreground'>
{table.getSelectedRowModel().rows.length} of{' '}
{table.getFilteredRowModel().rows.length} row(s) selected.
</div> You could use the following to show the number of rows selected : Object.keys(table.getState().rowSelection).length And a count from your DB to show the total. You get something like
|
Having the same issue... |
Describe the bug
I've noticed differences in how selection of all rows is treated when using standard vs. server-side pagination.
As we see in the official example here: https://tanstack.com/table/v8/docs/examples/react/row-selection toggling "all rows selection" affects truly all rows in the table. The rows are present from the start, so we we don't need to define
getRowId
, everything is fine.But when we use server-side pagination, we'd need to provide the
getRowId
since we can't rely on the raw row index since it resets for every page (I suppose that's the reason?). Otherwise we'll notice a side-effect like here #4555 or #3619.However, with
getRowId
defined thetable.getToggleAllRowsSelectedHandler()
affects only rows on the current page (even though there is a special handler for that? This onetable.getToggleAllPageRowsSelectedHandler
?). Furthermore, thetable.getIsAllRowsSelected()
also returns true when just the entries on the current page are selected.So I'm wandering, if this behaviour is intended, then why when using the "standard" pagination the
table.getToggleAllRowsSelectedHandler()
affects all pages (and with server-side pagination only the current page)? How can I achieve the same behaviour when using the server-side pagination?I "created" a codesandbox by merging the two examples: https://tanstack.com/table/v8/docs/examples/react/row-selection and https://tanstack.com/table/v8/docs/examples/react/pagination-controlled
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/tanstack-table-controlled-pagination-row-selection-fbkc6x?file=%2Fsrc%2Fmain.tsx&selection=%5B%7B%22endColumn%22%3A8%2C%22endLineNumber%22%3A151%2C%22startColumn%22%3A8%2C%22startLineNumber%22%3A151%7D%5D
Steps to reproduce
Using the linked Codesanbox:
"Bug" 1
"Bug" 2
Expected behavior
I'd expect that the kind of pagination doesn't affect how "toggle all rows selection" works.
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
macOS, Chrome
react-table version
8.8.4
TypeScript version
5.6.4
Additional context
No response
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: