Code Monkey home page Code Monkey logo

Comments (7)

cherniavskii avatar cherniavskii commented on August 15, 2024 2

I've opened #12870, and I'll check with the team if there are any objections to merging it 👍🏻

from mui-x.

AdamBeWell avatar AdamBeWell commented on August 15, 2024 1

@cherniavskii Yes, that is exactly the behavior I was expecting and the way I was trying to achieve it.
The value is capitalized but the formattedValue is lowercase and updates properly when editing.

from mui-x.

michelengelen avatar michelengelen commented on August 15, 2024

Hey @AdamBeWell ... columns with a valueGetter are not meant to be editable. The example you gave is actually a good one: The value in the fullName column is being generated from 2 other columns and therefore we are not able to determine which of the 2 columns should be updated when editing the value there.

There is also a difference between valueGetter and valueFormatter. You can have a field that uses valueFormatter and still be editable (this is a good example of this):

valueFormatter: (value) => {
  if (value == null) {
    return '';
  }
  return `${value.toLocaleString()} %`;
},

Here we format the stored value (a number) and add a % to the end to show that this is a percentage value.

@cherniavskii we could make this clearer with a warning in the valueGetter section. Should we add a recipe for this?

from mui-x.

AdamBeWell avatar AdamBeWell commented on August 15, 2024

From my understanding, an editable column with a valueGetter must also have a valueSetter. I see no problem with that and that's how it is in my example and everywhere else in my code.
I actually didn't know that you could omit valueGetter, I guess it falls back to the field name at that point.

The value in the fullName column is being generated from 2 other columns and therefore we are not able to determine which of the 2 columns should be updated when editing the value there.

That shouldn't matter here because of valueSetter.
After calling setEditCellValue I would expected the edited value to go through valueParser, then valueSetter and then the GridRenderEditCellParams of renderEditCell to be updated with value from valueGetter and formattedValue from valueFormatter with the new edited value.
And this is how it seems to work, except for formattedValue in GridRenderEditCellParams is seemingly not updated or is always based on the original value.

In short, formattedValue in GridRenderEditCellParams is basically useless as it is.
Looking into it a bit more, I see that the formattedValue I'm using in GridRenderEditCellParams is extended from GridCellParams and probably not meant no be updated unlike value which is extended from both GridEditCellProps and GridCellParams.

My actual use case was for a column with persisted user ids but with displayed user names, even when editing.
valueGetter gets the ids, valueFormatter translates those ids to their names, valueParser translates the new names from the new value back to ids and valueSetter sets the new ids.
And that works for the first render but once you try to edit the value, no change is recorded, like in my example.

There is also a difference between valueGetter and valueFormatter. You can have a field that uses valueFormatter and still be editable (this is a good example of this):
Here we format the stored value (a number) and add a % to the end to show that this is a percentage value.

But if you want to display the % sign when the cell is being edited, you can't. You could clean up the value/remove the sign after in valueParser. It doesn't really make sense in this case but I think you should be able to.

from mui-x.

cherniavskii avatar cherniavskii commented on August 15, 2024

Hey @AdamBeWell
This is a very interesting and unusual use case, thanks for the detailed explanation!
I'll see what we can do on our side!

from mui-x.

cherniavskii avatar cherniavskii commented on August 15, 2024

@AdamBeWell Can you take a look at this demo?
Is this what you're looking for?

from mui-x.

github-actions avatar github-actions commented on August 15, 2024

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@AdamBeWell: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction 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.