Comments (7)
I've opened #12870, and I'll check with the team if there are any objections to merging it 👍🏻
from mui-x.
@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.
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.
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.
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.
@AdamBeWell Can you take a look at this demo?
Is this what you're looking for?
from mui-x.
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)
- [data grid] render a value for the leave field HOT 12
- [TreeView] Deprecate `ContentComponent` and `ContentProps` props on `TreeItem`
- [data grid] Page Size Options dropdown missing HOT 2
- [fields][TimeField] Adapt delta calculation for meridiem HOT 1
- [TreeView] Visually select the ancestors of a selected item HOT 3
- [data grid] Missing translation for key `headerFilterOperatorBetween` HOT 7
- [data grid] Row css class for striped rows HOT 20
- [data grid] Textfield with in renderCell not storing value HOT 8
- [data grid] Format row count numbers in pagination HOT 13
- [pickers] AdapterDateFnsV3: Wrong types generated HOT 6
- [data grid] useGridRootProps should only be used inside the DataGrid, DataGridPro or DataGridPremium component HOT 3
- [data grid] infinite loop occurs under certain circumstances HOT 10
- New component Barcode & QRCode & scanner HOT 1
- [pickers] DateBuilderReturnType provides wrong type with no arg HOT 3
- [data grid] Add support for async valueOptions callback HOT 1
- [pickers][DateTimePicker] page scrolls when mouse is moved outside of it when using hour/minute picker HOT 5
- [docs] Tree View: check children, uncheck parents HOT 3
- [data grid] Column resizing doesn't work from group HOT 2
- [pickers][Datepicker][AdapterDateFnsV3] unable to set single digit day of month format HOT 4
- [charts] LineChart doesn't draw graph on page load HOT 1
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.