-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Partial pagination is broken #379
Comments
I've found the code resposnsible for this problem. It's this piece of code in const totalPages = Math.ceil(total / query.perPage) || 1;
useEffect(() => {
if (
query.page <= 0 ||
(!loading && query.page > 1 && ids.length === 0)
) {
// Query for a page that doesn't exist, set page to 1
queryModifiers.setPage(1);
} else if (!loading && query.page > totalPages) {
// Query for a page out of bounds, set page to the last existing page
// It occurs when deleting the last element of the last page
queryModifiers.setPage(totalPages);
}
}, [loading, query.page, ids, queryModifiers, total, totalPages]); Changing |
Hello, |
Partial pagination will be back in 3.0.0 version (RC 0 is already out). |
API Platform version(s) affected: 2.6.3 & 2.6.4 and probably older versions
Description
When partial pagination is enabled, pagination in admin stops working. Each time the user clicks “Next” a proper request is being sent, but just after admin gets a response, there is another request triggered returning to page 1.
How to reproduce
You may just use Api Platform distribution: https://github.com/api-platform/api-platform/releases, then after setting it up add some records to the DB (e.g.
INSERT INTO greeting VALUES (generate_series(100,1000), 'Hello no. ' || generate_series(100,1000)::text);
) and then, enable partial pagination insrc/Entity/Greeting.php
:Possible Solution
Looks like solution with negative
total
should be abandoned, and it should be replaced with something else, maybe thatmeta
feature would help: marmelab/react-admin#4834, but still I don't have any idea what should be put insidetotal
when we don't really know how many records there are... I couldn't find the code that checks the value oftotal
parameter and causes that redirect topage=1
, so I don't know if there's a possibility to suppress that behaviour. If anyone knows where that code is, I'd be grateful for leaving a comment :-).Additional Context
Looks like the problem is in
admin/src/hydra/dataProvider.js
lines 420 - 429. Partial pagination support has been added (#297) by settingtotal
to negative numbers:Looks like now something (react-admin?) validates that number and if it's negative or even “invalid” (AFAIR I found it has to be bigger than
page * perPage
), then it triggers some kind of refresh / refetch with page set to1
.When I commented out:
and hardcoded
total: 1000
, and then changedadmin/src/list/Pagination.js
to behave as if there wastotal < -1
:The pagination started to work properly.
The text was updated successfully, but these errors were encountered: