table
table copied to clipboard
Expanding is not working with `manualPagination` and with truthy `paginateExpandedRows`
Describe the bug
Hi! In the current project, we have two types of tables: controlled and independent. Both of them have the default options for pagination and for expanding:
const defaultOptions = {
// We don't want to slice expanded rows
paginateExpandedRows: false,
getPaginationRowModel: getPaginationRowModel(),
getExpandedRowModel: getExpandedRowModel(),
}
The controlled table can be customized by a developer, especially pagination (he can set manualPagination
in true
) if he doesn't want to use internal pagination. The other type of table might not be customizable and pagination is fully controlled by logic around the current library. So, in the first case, expanding functionality becomes broken when we are trying to use external pagination params and setting manualPagination
in true
. I've found that the course of the problem is here:
https://github.com/TanStack/table/blob/main/packages/table-core/src/utils/getExpandedRowModel.ts#L22
After that, I tried to fix it and just added a simple check to getExpandedRowModel
:
function getCustomExpandedRowModel<TData extends RowData>(): (
table: Table<TData>
) => () => RowModel<TData> {
return table =>
memo(
() => [
table.getState().expanded,
table.getPreExpandedRowModel(),
table.options.paginateExpandedRows,
table.options.manualPagination,
],
(expanded, rowModel, paginateExpandedRows, manualPagination) => {
if (
!rowModel.rows.length ||
(expanded !== true && !Object.keys(expanded ?? {}).length)
) {
return rowModel
}
// Here is the fix
if (!paginateExpandedRows && !manualPagination) {
// Only expand rows at this point if they are being paginated
return rowModel
}
return expandRows(rowModel)
},
{
key: 'getExpandedRowModel',
debug: () => table.options.debugAll ?? table.options.debugTable,
}
)
}
It's also presented in an example. But for now, we have other options to avoid this problem:
- Don't use
paginateExpandedRows
infalse
withmanualPagination
- Create a custom
getExpandedRowModel
and copy the internal logic from the repo - Update somehow
getExpandedRowModel
and don't usepaginateExpandedRows
inside
I think, the first choice is the easiest one, but it must be documented (because it's very unclear). In other case, if the fix in the example is looking good for you, I can make a PR with tests)
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/dreamy-euler-fjgltr
Steps to reproduce
- Open an example
- Try to expand any row
Expected behavior
A row must be expanded
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Any
react-table version
v8.10.3
TypeScript version
No response
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.
i think you meant falsy paginateExpandedRows
, in your example it's set to false, I am having the same issue
i think you meant falsy
paginateExpandedRows
, in your example it's set to false, I am having the same issue
Yeah, thx for the correction)