absent-sapphire
absent-sapphireā€¢17mo ago

Pagination datagrid

sorry for my English, our api uses page=x for pagination, by default it returns 20 results per page, so I would like to know how to include this in the datagrid pagination, I imagine you can just change the current with something like "current +1", I just don't know how to do this inside the datagrid
5 Replies
exotic-emerald
exotic-emeraldā€¢17mo ago
Hi again, which data provider u are using ? I have to ask to understand better.
absent-sapphire
absent-sapphireā€¢17mo ago
i using a custom data provider getList: async ({ resource, hasPagination = true, pagination = { current: 1}, filters, sort, }) => { const url = ${apiUrl}/${resource}/; const { current = 1} = pagination ?? {}; const queryFilters = generateFilter(filters); const query: { page?: number; page_size?: number; _sort?: string; _order?: string; } = hasPagination ? { page: current, } : {}; and, the api return: "count": xxx, "next": "apiXXXXX/?page=2", "previous": null, "results": []
exotic-emerald
exotic-emeraldā€¢17mo ago
Your data-provider seems correct. useDataGrid pagination should works out of the box. do you have any errors on console ? "results": [] is empty. is this the problem ? I created example with setCurrent https://codesandbox.io/s/modest-orla-x6ht1o?file=/src/pages/posts/list.tsx
absent-sapphire
absent-sapphireā€¢17mo ago
this worked, it was exactly what I needed, thank you very much
exotic-emerald
exotic-emeraldā€¢17mo ago
I'm glad to hear that šŸ™ your welcome