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] Sync date column value when entering edit mode by pressing a digit #8364

Merged
merged 3 commits into from Apr 6, 2023

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Mar 23, 2023

Fixes #8302

Preview: https://deploy-preview-8364--material-ui-x.netlify.app/x/react-data-grid/editing/#making-a-column-editable

The solution I implemented here was not what I intended to do in #8302 (comment). When a digit key is pressed, we update the input value to be equal to the key pressed. In a type=date input, this updates the first date component, which could be the day or month, depending on the locale. Calling the value parser won't work because we don't know the date format (it's defined by the browser) to replace the right date component. The solution used here is a workaround involving calling setEditCellValue as soon as the input is rendered and a digit key press was the reason for the cell to enter edit mode.

@m4theushw m4theushw added the component: data grid This is the name of the generic UI component, not the React module! label Mar 23, 2023
@mui-bot
Copy link

mui-bot commented Mar 23, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-8364--material-ui-x.netlify.app/

Updated pages

No updates.

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 729.3 1,251.3 729.3 960.12 225.347
Sort 100k rows ms 687.7 1,373.4 1,215.3 1,092.92 229.317
Select 100k rows ms 218.5 498.3 318.8 323.06 99.472
Deselect 100k rows ms 147.4 292.7 197.6 217.86 51.334

Generated by 🚫 dangerJS against 599b8e0

@@ -98,24 +98,32 @@ function GridEditDateCell(props: GridEditDateCellProps) {
const ownerState = { classes: rootProps.classes };
const classes = useUtilityClasses(ownerState);

const hasUpdatedValueOnRender = React.useRef(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const hasUpdatedValueOnRender = React.useRef(false);
const hasUpdatedEditValueOnMount = React.useRef(false);

Would this name better reflect what it's used for?

@@ -145,9 +153,23 @@ function GridEditDateCell(props: GridEditDateCellProps) {
}
}, [hasFocus]);

const meta = apiRef.current.unstable_getEditCellMeta(id, field);

const handleInputRef = async (el: HTMLInputElement) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const handleInputRef = async (el: HTMLInputElement) => {
const handleInputRef = (el: HTMLInputElement) => {

@m4theushw m4theushw merged commit dca019f into mui:master Apr 6, 2023
15 checks passed
@m4theushw m4theushw deleted the sync-value-date-column branch April 6, 2023 12:14
@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Call value parser when entering edit mode by pressing printable key
4 participants