-
-
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
[DataGrid] Fix gridPageCountSelector
selector
#8450
Comments
For I tried to do it on your codesandbox example. Here's the updated codesandbox: https://codesandbox.io/s/awesome-orla-4jcc7h |
Thank you for getting back to me so quickly! Unfortunately, I don't think your response addresses the issue I reported. The issue I observed relates to "page count" in stead of "row count". By the way, I encountered this issue when I was trying to migrate data grid to v6. |
@homerchen19 You are right, my bad, It had to be Actually the confusion comes between There is a small interface difference between the two, i.e Compatability with v5: In v6, we removed this state as the value could easily be computed on runtime and doesn't make sense to be stored in a dedicated state. Benefits: Simplify the state and avoid unnecessary complexity. You can compute the value like being done in the default mui-x/packages/grid/x-data-grid/src/components/GridPagination.tsx Lines 36 to 39 in 6fe709b
So essentially, this is an intended behavior and not a bug. However, I think removing The -const pageCount = useGridSelector(apiRef, gridPageCountSelector);
+const pageSize= useGridSelector(apiRef, gridPageSizeSelector);
+const visibleTopLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
+const pageCount = getPageCount(rootProps.rowCount ?? visibleTopLevelRowCount , pageSize); The potential options that we have:
To me, option 2 seems more like it. What do you think @mui/xgrid team 🤔 |
Thank you for reporting this issue, as I am experiencing the same when migrating to v6. Is there an ETA for when the fix will be merged? |
@MBilalShafi const apiRef = useGridApiContext();
const pageSize = useGridSelector(apiRef, gridPageSizeSelector);
const visibleTopLevelRowCount = useGridSelector(
apiRef,
gridFilteredTopLevelRowCountSelector
);
const rootProps = useGridRootProps();
const pageCount = getPageCount(
rootProps.rowCount ?? visibleTopLevelRowCount,
pageSize
); Would it make sense to pass already calculated |
@samanthajuniper You can apply the suggestion from #8450 (comment) as a workaround. Here's a working demo: https://codesandbox.io/s/sharp-volhard-zhj42z |
Can we at least get this mentioned in the migration docs, please? It has been three months since this was pointed out. It's a pretty serious bug, as anyone who migrates to v6 won't be able to use custom pagination unless they search the github issues and find this thread. |
@Dustin-Digitar apologies for the delay, we'll try to prioritize this asap |
rowCount
and pageCount
props to pagination
slot
I think we should keep the selector and make it work properly. I think the real issue is that our selectors don't have access to everything they need, and that to solve it we should store more stuff where it needs to be: in the grid state. We're pulling arguments from different react hooks (component-level We had the same problem with the visible pinned columns in the sticky PR, for context read this. Our selectors should have everything they need, this allows us to build our more complex selectors as a composition over primitive selectors, instead of moving the computations where they don't belong. |
Wasted an hour playing process of elimination, only to find that the problem had to come from MUI and found this issue. After 6 versions, I really thought that basic pagination would be stable at this point... |
This makes sense, but I'm a bit worried that putting |
Yeah I haven't made up my mind as to what to put in the state. Putting the props directly is unlikely to be good because most of our users probably don't memoize the props they pass to us properly. The best option would probably be to select which props we put in the state and use something like Also I'll note that our expensive complex selectors should be cached on the subparts of the state they depend on, like |
The state has reactivity via |
@romgrk @MBilalShafi I've created an issue for a general solution for this problem: #11549 |
👍 To me it totally makes sense to start with adding a couple of props we face immediate challenges with, during the process, we can analyze the broader problem addressed in #11549 |
I think we should go with the clean general solution as it's not that much more expensive to implement than passing props to |
rowCount
and pageCount
props to pagination
slotgridPageCountSelector
selector
I've lost many hours today with this bug. This should be fixed or at least documented on the component page. |
How did we do @homerchen19? |
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/brave-goldberg-3lve8e?file=/demo.tsx
Current behavior 😯
pageCount
in the following code always return1
.From the screenshot, it is apparent that there are 100 rows in total, but the page count is displaying as 1.
Expected behavior 🤔
Based on the codesandbox example, I believe the
pageCount
should be calculated using the formulaMath.ceil(rowCountState / pageSize)
, which would result in a value of20
.Context 🔦
No response
Your environment 🌎
npx @mui/envinfo
Order ID or Support key 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: