Comments (6)
Hey @mororyou and thanks for raising this.
I can confirm that this is a bug (or at least an inconsistency) that we can improve upon.
I did play around with it a bit and found an easy way to fix this for boolean
s and potentially all other values as well (if we do decide to introduce default values for those:
diff --git a/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts b/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts
index 25c7cfdb5..3108844a7 100644
--- a/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts
+++ b/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts
@@ -329,8 +329,24 @@ export const useGridCellEditing = (
const { id, field, deleteValue, initialValue } = params;
let newValue = apiRef.current.getCellValue(id, field);
- if (deleteValue || initialValue) {
- newValue = deleteValue ? '' : initialValue;
+
+ if (deleteValue) {
+ const fieldType = apiRef.current.getColumn(field).type;
+ switch (fieldType) {
+ case 'boolean':
+ newValue = false;
+ break;
+ case 'date':
+ case 'dateTime':
+ case 'number':
+ newValue = undefined;
+ break;
+ case 'singleSelect':
+ case 'string':
+ default:
+ newValue = '';
+ break;
+ }
+ } else if (initialValue) {
+ newValue = initialValue;
}
const newProps = {
It would be beneficial if we could add a test or two as well to prevent regressions.
Since this is a fairly easy task to do I will also open this up as a good first issue
.
Thanks again for reporting it! 🙇🏼
from mui-x.
I've been thinking about the suggestion to set the singleSelect field's value to an empty string ('') upon a delete key event.
From what I've gathered, it might enhance user experience to more explicitly indicate a 'no selection' state with null
or undefined
for singleSelect fields. This seems like it could more clearly align with a user's intent to 'unselect' and help in maintaining data consistency.
Since I'm new and still learning about the project's data handling, I would greatly appreciate any additional insights on this matter. 😊
from mui-x.
That sounds about right. I just left it as an empty string because the previous implementation was using it as well ...
if (deleteValue || initialValue) {
newValue = deleteValue ? '' : initialValue;
...
I would be fine with null
from mui-x.
hi @michelengelen, can I work on this issue? Kindly assign it to me! 🙏
from mui-x.
+ case 'singleSelect':
+ case 'string':
+ default:
+ newValue = '';
+ break;
For singleSelect, is it also intended to fallback into empty string?
from mui-x.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.
How did we do @mororyou?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.
from mui-x.
Related Issues (20)
- [data grid] How to autosize and header filters work well? HOT 4
- [pickers] Change of locale adapter import for moment.js HOT 2
- [pickers] Date Calendar like an actual Outlook-ish calendar HOT 4
- [data grid] Possibility to save changes in data grid, like column sorting, hiding ordering HOT 2
- [pickers] Translating page in Edge make calendar show March when not March HOT 5
- [data grid] tests fail when calling setCellFocus HOT 1
- [docs] Recommended Pickers styling approach shown on all styling approaches HOT 3
- [pickers] MUI DateRangePicker property "name" doesnt render HOT 3
- [charts][RFC] Replace `DefaultXxxx` by the usage of hooks
- [charts] Remove deprecated props HOT 1
- [data grid] Cell stealing focus from modal and onClicks for buttons rendered inside cells fire when the user hits the enter key HOT 3
- Create PDF component HOT 7
- [data grid] is there anyway to avoid copy paste functionality from one column to another? HOT 11
- [tree view][TreeItem] Add support for `href` attribute HOT 5
- [data grid] Check the grouped child rows on select of the grouped row HOT 3
- [data grid] Resizing columns gets misaligned HOT 1
- [charts] Get access to the data outside of the SVG
- [charts] Document the usage of foreingObject
- [fields][DateField] on Android: using DateField on firefox doesn't work HOT 4
- [data grid] Impact of not renewing license for small changes and bug fixes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui-x.