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

[DataGrid] Option to Disable Pagination while server request is loading #2843

Open
2 tasks done
asyrialaK opened this issue Oct 11, 2021 · 5 comments
Open
2 tasks done
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Pagination Related to the data grid Pagination feature new feature New feature or request waiting for 👍 Waiting for upvotes

Comments

@asyrialaK
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

When i am using server side pagination my goal is for a user to be able paginate and get the next page.

We are using a graphQL API, and cursor based pagination. For pagination to work as intended, we need the request for the current page to complete, so we can get the cursors for the next page. As a result, we'd like the ability to disable the pagination buttons while content loads.

The inability to do this allows a user to hit next page any amount of times, and still request content based off the next page from the content currently being displayed.

An easy way to replicate this would be to hook up a table to server data with cursor based pagination, then throttle your speed. Then do the following

  1. Let the table load
  2. Hit next page 5 times
  3. Each request will be using the end cursor from page 1
  4. Page six will load with the results from page 2

Examples 🌈

No response

Motivation 🔦

I am trying to use the datagrid in a way where server side pagination using cursors provides us the ability to go to the next page and reliably get the next results.

Order ID 💳 (optional)

No response

@asyrialaK asyrialaK added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 11, 2021
@DanailH
Copy link
Member

DanailH commented Oct 12, 2021

Hi, @asyrialaK thanks for raising this.

A possible solution is for you to provide your own pagination via the components prop (you can find more about it here https://mui.com/components/data-grid/components/#pagination) and control when it is enabled or disabled. If you use DataGridPro you can control it using the apiRef and access to rootProps to know when the grid is loading and when not. I've prepped a quick demo to showcase my idea. You can find it here: https://codesandbox.io/s/serverpaginationgrid-material-demo-forked-eipvy?file=/demo.tsx:1877-1887

@asyrialaK
Copy link
Author

Thanks for providing a workaround for this! That approach would definitely enable us to prevent multiple paging to prevent bad pagination.

I'd love to see something like this baked into the base tables loading state to be able handle cursor-based server data by default.

@flaviendelangle flaviendelangle changed the title [DataGrid] - Option to Disable Pagination while server request is loading [DataGrid] Option to Disable Pagination while server request is loading Nov 8, 2021
@flaviendelangle flaviendelangle added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request waiting for 👍 Waiting for upvotes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 8, 2021
@oliviertassinari oliviertassinari added the feature: Pagination Related to the data grid Pagination feature label Jan 29, 2022
@kovryzhenko
Copy link

idk why we still have to make some workaround for this :(
we need some flag for this from the box.
ty.

@jonahsol
Copy link

jonahsol commented Aug 29, 2023

I'm using 6.8.0 and we can pass prop slotProps:

<DataGrid
    ...
    slotProps={{
        pagination: {
            prevIconButtonProps: {
                disabled: myQuery.isFetchingPreviousPage,
            },
            nextIconButtonProps: {
                disabled: myQuery.isFetchingNextPage,
            },
            SelectProps: {
                disabled: myQuery.isFetching,
            },
        },
    }}
/>

with the default <Pagination /> component these props are passed to https://mui.com/material-ui/api/table-pagination/.

@ducnhh8
Copy link

ducnhh8 commented Nov 6, 2023

I'm using 6.8.0 and we can pass prop slotProps:

<DataGrid
    ...
    slotProps={{
        pagination: {
            prevIconButtonProps: {
                disabled: myQuery.isFetchingPreviousPage,
            },
            nextIconButtonProps: {
                disabled: myQuery.isFetchingNextPage,
            },
            SelectProps: {
                disabled: myQuery.isFetching,
            },
        },
    }}
/>

with the default <Pagination /> component these props are passed to https://mui.com/material-ui/api/table-pagination/.

Be careful when using this though because this will overwrite the default behavior of the previous and next buttons to be disabled on the first and last page, respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Pagination Related to the data grid Pagination feature new feature New feature or request waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

7 participants