-
-
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] Implement control state/prop for all props using useGridControlState hook #2044
Comments
FYI I'm picking up control sort model |
For the pagination The Descriptions of the rows
Descriptions of the current pagination
For this part, we can have a controlled / uncontrolled behavior. <Grid page={0} pageSize={20} /> Instead of <Grid paginationModel={{ page: 0, pageSize: 20 }} /> To migrate to a behavior closer to the other controlled model, I propose to :
If we do not want to do this breaking change, I can keep the 2 props and do a little bit a magic in
|
@flaviendelangle you just need to bind the props with their onChange events onPageChange?: (page) => void;
onPageSizeChange?: (pageSize) => void; We don't need to control every prop, just the ones that have an onChange handler. |
So you would do something like that ? React.useEffect(() => {
apiRef.current.updateControlState<number>({
stateId: 'page',
propModel: props.page,
propOnChange: props.onPageChange,
stateSelector: (state) => state.pagination.page,
onChangeCallback: (model) => {
apiRef.current.publishEvent(GRID_PAGE_CHANGE, model);
},
});
}, [apiRef, props.page, props.onPageChange]);
React.useEffect(() => {
apiRef.current.updateControlState<number>({
stateId: 'pageSize',
propModel: props.pageSize,
propOnChange: props.onPageSizeChange,
stateSelector: (state) => state.pagination.pageSize,
onChangeCallback: (model) => {
apiRef.current.publishEvent(GRID_PAGE_SIZE_CHANGE, model);
},
});
}, [apiRef, props.pageSize, props.onPageSizeChange]); An issue I see with these 2 I can avoid updating the two variables together, but it makes a strange code : https://github.com/mui-org/material-ui-x/pull/2099/files#diff-88ab07d0295dc05cfb45a167032079961737adbcc04e547dafd7762f817bf5d7R93 This won't fix this |
I'm closing as we have migrated all the controlled props, well-done @dtassone, @m4theushw, @flaviendelangle. |
Hello and apologize for spamming here, I can give I also had a look at the "Story" tab here https://deploy-preview-2099--material-ui-x.netlify.app/storybook/?path=/story/x-grid-tests-sorting--server-side-sorting&globals=measureEnabled:false but sadly that didn't help me at all. If it is even relevant, not sure. Could you please give me a very brief example/a few hints on how this is supposed to work now? That is how am I supposed to change the Thank you very much for all your help. EDIT: I have my answer now and it was enough to see this updated documentation https://material-ui.com/components/data-grid/sorting/ which is quite self-explanatory. So please disregard this comment. |
link to #190
Summary 💡
Following core work of #1823, we now have to bind all props with their onChange handler.
Todo includes:
Examples 🌈
Motivation 🔦
Order id 💳
The text was updated successfully, but these errors were encountered: