Skip to content

Commit 2797c76

Browse files
committed
refactor: update editable logic to new function
1 parent 684f0f2 commit 2797c76

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/toolpad-studio-components/src/DataGrid.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export function parseColumns(columns: SerializableGridColumns, isEditable?: bool
483483
return columns.map(({ type: colType, ...column }) => {
484484
const isIdColumn = column.field === 'id';
485485

486-
let baseColumn: Omit<GridColDef, 'field'> = { editable: isEditable };
486+
let baseColumn: Omit<GridColDef, 'field'> = {};
487487

488488
if (isIdColumn) {
489489
baseColumn = {
@@ -1270,7 +1270,17 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
12701270
}, [nodeRuntime, rows]);
12711271

12721272
const renderedColumns = React.useMemo<GridColDef[]>(() => {
1273-
const result = [...columns];
1273+
const mapEditableToColumns = columns.map((column) => {
1274+
if (column.editable || column.editable === false) {
1275+
return column;
1276+
}
1277+
1278+
column.editable = isRowUpdateModelAvailable;
1279+
1280+
return column;
1281+
});
1282+
1283+
const result = [...mapEditableToColumns];
12741284

12751285
if (getProviderActions) {
12761286
result.push({
@@ -1284,7 +1294,7 @@ const DataGridComponent = React.forwardRef(function DataGridComponent(
12841294
}
12851295

12861296
return result;
1287-
}, [columns, getProviderActions]);
1297+
}, [columns, getProviderActions, isRowUpdateModelAvailable]);
12881298

12891299
const appHost = useAppHost();
12901300
const isProPlan = appHost.plan === 'pro';

0 commit comments

Comments
 (0)