Code Monkey home page Code Monkey logo

Comments (6)

michelengelen avatar michelengelen commented on September 18, 2024 2

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 booleans 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.

sooster910 avatar sooster910 commented on September 18, 2024 2

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.

michelengelen avatar michelengelen commented on September 18, 2024 2

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.

sooster910 avatar sooster910 commented on September 18, 2024

hi @michelengelen, can I work on this issue? Kindly assign it to me! 🙏

from mui-x.

LumaKernel avatar LumaKernel commented on September 18, 2024

@michelengelen

+          case 'singleSelect':
+          case 'string':
+          default:
+            newValue = '';
+            break;

For singleSelect, is it also intended to fallback into empty string?

from mui-x.

github-actions avatar github-actions commented on September 18, 2024

⚠️ This issue has been closed.
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.