> = {
json: {
valueFormatter: ({ value: cellValue }: GridValueFormatterParams) => JSON.stringify(cellValue),
},
- datetime: {
- valueFormatter: ({ value: cellValue }: GridValueFormatterParams) =>
- typeof cellValue === 'number' ? new Date(cellValue) : cellValue,
+ date: {
+ valueGetter: dateValueGetter,
+ },
+ dateTime: {
+ valueGetter: dateValueGetter,
},
};
@@ -286,6 +294,13 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
const columns: GridColumns = React.useMemo(() => parseColumns(columnsProp || []), [columnsProp]);
+ // The grid doesn't react to changes to the column prop, so it needs to be remounted
+ // when that updates to reflect changes made in the editor.
+ const key = React.useMemo(
+ () => [rowIdFieldProp ?? '', getObjectKey(columnsProp)].join('::'),
+ [columnsProp, rowIdFieldProp],
+ );
+
return (
();
+let nextId = 0;
+
+function getNextId(): string {
+ const id = `object-id::${nextId}`;
+ nextId += 1;
+ return id;
+}
+
+/**
+ * Used to generate ids for object instances.
+ */
+export function getObjectKey(object: any): string {
+ let id = weakMap.get(object);
+ if (!id) {
+ id = getNextId();
+ weakMap.set(object, id);
+ }
+ return id;
+}