-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Server-side pagination for an unknown number of items #409
Comments
@thomasdowell Thanks for the feature request. The grid doesn't support the unknown last row case yet. This request is close to #404 but for when |
Are there any known workarounds to this? I'm using DynamoDB and item count is either estimated (to get quickly) or expensive to get accurately. It would be nice if the data grid just allowed the next page to load and disable showing the total count in this case. I see the infinite scroll for client side was marked important and closed, @oliviertassinari I see you marked that issue as important. Seeing dynamo's (and nosql in general) growth in popularity I would assume many people are going to start running into this issue (unless there is a valid workaround I'm not aware of)? |
@ahurlburt I had the same experience with PostgreSQL after 1m rows on a table. Regarding the possible solution of this problem, I think that there are two different paths that we could follow (complementary):
This duality of choices is similar to what @DanailH is working on for #1247. He started by building the missing API for option 1 (not the same issue as we talk here) |
I'm also working on at least two use cursor-based pagination cases where I don't know the total amount of rows, until I hit the last page. (One is dynamodb) This is the main reason why getting DataGridPro hasn't been worth it for me. |
This issue is affecting me as well! Right now can't use the data-grid because of this limitation about the row count. I had to make a custom list with infinite scroll. +1 |
Same here folks, the total items is unknown till reaching that last page |
Workaround 👇
|
Even for teams not using Relay, the Relay pagination spec is a reliable and consistent spec for cursor-based pagination: https://relay.dev/docs/guided-tour/list-data/pagination We don't use Relay, but our pagination interface matches this, and it would be great if
This world speaks to many of the commenters above, where you don't have a total row count and you might not even know what page you're on, but you're getting UI wise, this means we aren't showing Just a thought — hope it helps! |
In the spirit of temporary workarounds, this hook manages to encapsulate the logic we need to apply in the meantime — in case others find it useful! export function useGridPagination() {
const [page, setPage] = useState(0);
const [pageSize, setPageSize] = useState(10);
const {
paginationState,
fetchPreviousPage,
fetchNextPage,
resetPaginationState,
} = usePagination(pageSize);
useEffect(() => {
if ((paginationState.first ?? paginationState.last) !== pageSize) {
resetPaginationState();
}
}, [paginationState, pageSize, resetPaginationState]);
const handlePageChange = useCallback(
(newPage: number, pageInfo?: GQPageInfo | null) => {
if (!pageInfo) return;
setPage(newPage);
if (newPage <= page) {
fetchPreviousPage(pageInfo);
} else {
fetchNextPage(pageInfo);
}
},
[fetchNextPage, fetchPreviousPage, page]
);
const gridPaginationProps = useCallback(
(pageInfo?: GQPageInfo | null) => ({
pagination: true,
paginationMode: 'server' as 'server',
pageSize,
onPageSizeChange: (newPageSize: number) => setPageSize(newPageSize),
rowsPerPageOptions: [10, 25, 100],
page,
rowCount: pageInfo?.hasNextPage
? Number.MAX_VALUE
: pageSize * (pageInfo?.hasPreviousPage ? 2 : 1),
onPageChange: (newPage: number) => handlePageChange(newPage, pageInfo),
}),
[handlePageChange, page, pageSize]
);
return {
paginationState,
gridPaginationProps,
};
} Then the grid just needs the following: <DataGrid
rows={rows}
columns={columns}
{...gridPaginationProps(pageInfo)}
sx={{
'.MuiTablePagination-displayedRows': {
display: 'none', // 👈 to hide huge pagination number
},
}}
/> |
It's even more hacky, but I just did <DataGrid
rowCount={9999999999}
sx={{
".MuiTablePagination-displayedRows": {
display: "none",
},
}}
/> |
Would be perfect to have a custom render for the rowCount. I'd like to have the word Edit:
With the |
@thomasdowell: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
To enable server-side pagination for an unknown number of items in the TablePagination component, the value of the count prop must be -1. When the value of the DataGrid component's rowCount prop is set to -1, the server-side pagination functionality is not complete.
Current Behavior 😯
"Total rows: -1" is rendered and the onPageChange function is not triggered.
Expected Behavior 🤔
"Total rows: -1" should not render and the onPageChange function should trigger until there are no more pages to get from the server.
Steps to Reproduce 🕹
Steps:
rowCount={100}
torowCount={-1}
on line 55Context 🔦
Server-side pagination
Benchmark
The text was updated successfully, but these errors were encountered: