question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Partial Pagination Not Working for `ReferenceManyField`

See original GitHub issue

What you were expecting:

When the getManyReference method of the dataProvider returns pageInfo instead of total, partial pagination should be in effect for the pagination component passed to the ReferenceManyField component.

What happened instead:

When the getManyReference method of the dataProvider returns pageInfo instead of total, the pagination component passed to the ReferenceManyField component does not render at all.

Steps to reproduce:

  1. Pass a Pagination component to the ReferenceManyField: https://marmelab.com/react-admin/ReferenceManyField.html#pagination
  2. Have the getManyReference method of the dataProvider return pageInfo instead of total.

Other information:

This could be the culprit here as the pagination prop is not rendered unless total is defined.

Environment

  • React-admin version: 4.0.1
  • React version: 18.0.0
  • Browser: Chrome 103.0.5060.134

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
septentrion-730ncommented, Jul 27, 2022

Thanks for this helpful and almost perfect reporting!

Could you provide a behaviour reproduction sandbox?

  • a CodeSandbox forked from simple example V4 or v3
  • a link to a GitHub repo with the minimal codebase to reproduce the issue?

Many thanks for your help in this matter! 👍

0reactions
MichaelSandorcommented, Nov 3, 2022

For those who encounter this issue in the future, a workaround is to return total as null as part of the getManyReference method of the dataProvider.

As an example:

getManyReference: (resource, params) => {
   ...
   return httpClient.get(path).then(res => ({
      data: ...
      pageInfo: {
         ...
      },
      total: null,
   }))
   ...
}

This works because the ReferenceManyField only renders the pagination controls if total !== undefined as seen here:

https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/field/ReferenceManyField.tsx#L92

For those who use TypeScript, you can use the @ts-expect-error or @ts-ignore directives to suppress the type error that will arise (total is expected to be number or undefined).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination of `<ReferenceManyField>` · Issue #561 - GitHub
I just noticed that fetch all data was possible, so I commented to help people that might need it as a quick solution...
Read more >
Passing props to ReferenceArrayField doesn't seem to work
When passing the pagination, perPage and sort props to reference array component they don't seem to be applied. I have a similar view...
Read more >
react-admin/CHANGELOG and react-admin Releases (Page 2)
A frontend Framework for building B2B applications running in the browser on top of ... Fix <ReferenceManyField> does not show pagination when using...
Read more >
Source - GitHub
... Fix `<ReferenceManyField>` does not show pagination when using partial pagination ([#8354](https://github.com/marmelab/react-admin/pull/8354)) ...
Read more >
react-admin - Projects | FOSSA
... 7705-codesandbox-not-working-for-tutorial-example ... optional-basepath2; partial-pagination; pass-permissions-to-register-resource; password-input ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found