-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] combined usage of pagination and filter calls api twice with server-side data integration #15378
Comments
@MBilalShafi another one for you ... Seems like updating with rows prop is sub-optimal here. Would be better to use the @achoud444 regarding the API-interface: We do have documentation about that here. |
@achoud444 When using server-side pagination and (or) filtering the In the mentioned example, since there's no Now, when filtering on pages > 1, we have the
I added a rowCount in the above example to remove this from happening: https://codesandbox.io/p/sandbox/sleepy-sunset-fy2gnm?file=%2Fsrc%2FDemo.tsx But this is far from complete, the Tip If you are on a Pro or Premium plan, you might give the data source a try, which is an improved way to work with server-side data. Let me know if you have further questions. Thanks |
If you seem my exaple again. I have the
You have added twice here
Yes I have a Premium plan. But still can we do something here which prevents from calling it twice? |
Thanks @achoud444 for the clarification. Yes, I overlooked that part with the mui-x/packages/x-data-grid/src/hooks/features/pagination/useGridPaginationModel.ts Line 240 in ff680fd
I'll check and shortly update you with a possible solution. |
@achoud444 I think it's the correct behavior. Consider a scenario:
I visualized the API calls in the table below.
Does it make sense or does your backend implementation work differently? If so, some details about its inputs/outputs would be helpful. Or do you specifically want to skip the API call when |
In my opinion, whenever the user is on a page other than page 1 and applies a filter, the API request should be made with the filter applied and the page set to 1 ? |
That's where the second call of useEffect will run. After the filterModel change (1. run), which results in a pagination change (2. run) |
I think it's hard to reason about as a default behavior. What if filtering yields similar records? The page reset would be an unexpected behavior. Also, filtering doesn't necessarily yield page 1, it's basically the last page. (For example, if filtering yields 20 records, the last page would be 20/5 = 4) The behavior could be tested with client-side filtering. |
Even if the records are similar, the user would still need to search for the desired row within the page. For instance, if there are 20 records with a page size of 5, and the user is on page 2 when they apply a filter that yields 15 records, they would still need to locate their result. So, wouldn’t it be better to take them directly to page 1, allowing them to start their search from the beginning? |
👍 Although it seems an opinionated thing, it makes sense to me. Filtering usually gets followed up by locating the desired rows which makes more sense to be done from the beginning. However, there could be cases where the current behavior would make sense but I imagine those would be fewer. For benchmark, I've done a quick comparison with a few other Table/Grid libraries and it seems both the patterns are being used. Libraries that go to the last visible page on filtering.
Libraries that go to first page on filtering.
I'd be in favor of changing this behavior as part of v8 breaking changes. Wdyt @mui/xgrid? |
I have checked out other people experiences/expectations and I really liked this answer and its summary |
Wdyt about making this a bit adaptable to support both the use cases, keeping in mind that
Another option could be to make this behavior customizable by API ( |
I think that even for sorting, resetting is covering more use cases.
Agree with this (let's leave it for later) |
We discussed this today and made a decision to reset the page to 0 whenever the sorting model or filter model changes. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @achoud444 How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Steps to reproduce
Link to live example: (required)
Steps:
1.
2.
3.
Current behavior
I've implemented pagination and filtering, and everything works perfectly on page 1. However, when I navigate to page 2 or 3 and then apply a filter, it triggers the API call twice. Here’s a working example.
Additional questions:
Expected behavior
No response
Context
No response
Your environment
npx @mui/envinfo
Search keywords: [Datagrid]: Pagniation and filter calls api twice
The text was updated successfully, but these errors were encountered: