Skip to content
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

[BUG] Table pagination example is flawed #5757

Closed
ElementalWarrior opened this issue Mar 15, 2024 · 8 comments
Closed

[BUG] Table pagination example is flawed #5757

ElementalWarrior opened this issue Mar 15, 2024 · 8 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@ElementalWarrior
Copy link

Describe the bug

https://refine.dev/docs/examples/table/mui/cursor-pagination/

Firstly this example only works one direction. The back button just moves forward further.

Secondly, by taking this approach, changing filters or sort breaks the "current page" referenced. The ${pagestart} - ${pageEnd} count will be inaccurate.

I don't have a solution for cursor pagination, but this example is not something people should try to use.

Steps To Reproduce

  1. Go to https://refine.dev/docs/examples/table/mui/cursor-pagination/
  2. Click the next arrow
  3. click the prev arrow
  4. Note the timestamps only go in one direction

Expected behavior

previous button in pagination works. And there is an example with the datagrid that works properly.

Packages

refine/examples/table-material-ui-cursor-pagination

Additional Context

No response

@ElementalWarrior ElementalWarrior added the bug Something isn't working label Mar 15, 2024
@amrahs02
Copy link

Hi, I noticed the issue with cursor pagination. I'd like to help resolve it. Looking forward to contributing. Thanks!"

@amrahs02
Copy link

Hey @ElementalWarrior, I've analyzed the issue but need a visual aid to understand it better. Could you provide a video or image? It'll help me grasp the problem more effectively. Thanks!

@ElementalWarrior
Copy link
Author

Click the link, go to the demo, click forward and back on the pagination.

@amrahs02

This comment was marked as off-topic.

@ElementalWarrior
Copy link
Author

You didn't actually click the paging back and forth.

@ElementalWarrior
Copy link
Author

The issue is with the example, not the websites navigation

mkazin added a commit to mkazin/refine that referenced this issue Mar 18, 2024
In table-material-ui-cursor-pagination
Data provider was using the most recent date of any fetched data as an
"until" filter instead of paging, which caused both forward & backward
to go back in the Github API commit list.
@mkazin
Copy link

mkazin commented Mar 18, 2024

@ElementalWarrior thanks for the clarification. I see the behavior you described. There is indeed a problem with how the example sets up the datagrid.

Apparently each subsequent request to the Github API is using an until cursor whose value is the date of the last commit which was in the datagrid. Since this API request returns data in newest-first order, both backward and forward queries end up moving back in time.

Relevant code:

The API's until parameter is specified with a date here via cursor.next :

if (metaData?.cursor?.next) {
url = `${url}&until=${metaData.cursor.next}`;

This value is passed to the datagrid using the state variable next:

const { dataGridProps, tableQueryResult } = useDataGrid<ICommit>({
initialPageSize: 5,
metaData: {
cursor: {
next,

And the value of next is always being set to the date of the last row:

onPaginationModelChange={(model, details) => {
const lastRow = data?.data[data.data.length - 1];
const next = lastRow?.commit.committer.date;
if (next) {
setNext(next);
}
dataGridProps.onPaginationModelChange?.(model, details);
}}

I'm not sure if this customized pagination was intended to be part of this example. For most use-cases, what the component has built-in should serve and custom pagination seems sufficiently documented.

I tested commit 97b82a0 which removes the custom code in favor of the component's default implementation.

If customization was intended in this example, Github's API allows for a since parameter in addition to until, which would allow backward and forward traversal, but these parameters aren't explicitly documented for use in pagination.

@ElementalWarrior as someone who used this example, do you have thoughts on which you prefer?

Copy link

stale bot commented May 18, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label May 18, 2024
@stale stale bot closed this as completed May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants