editSelectOptions values and labels #1069
-
I'm in the process of evaluating changing from MUIX DataGrid to Material React Table, and I'm struggling a bit with a select input for editing a cell. I'm using editDisplayMode = "row", although I don't think this is important. The basic scenario is a select, with values, and localised labels. So far, I have two scenarios:
The problem is demonstrated quite well by the example at https://www.material-react-table.dev/?path=/story/features-editing-examples--edit-select-variant-alternate. This uses the full state name as the value, but when editing it is rendered as the state abbreviation (the label). I would want to always see the label. Any thoughts on this? I can work around it by using my option 2, and converting the label to value on save, but this seems unnecessarily unpleasant. thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I ended up solving this by essentially re-implementing packages/material-react-table/src/components/inputs/MRT_EditCellTextField.tsx to change the initialisation of the selector. I changed line 44 from |
Beta Was this translation helpful? Give feedback.
I ended up solving this by essentially re-implementing packages/material-react-table/src/components/inputs/MRT_EditCellTextField.tsx to change the initialisation of the selector. I changed line 44 from
const [value, setValue] = useState(() => cell.getValue<string>());
to
const [value, setValue] = React.useState(row.original[column.id]);
This is the only change required, it could be great if there was a column option to allow this rather than re-implmenting the whole component.