Skip to content

Commit ee91831

Browse files
authored
[DataGrid] Ignore preProcessEditCellProps for non-editable columns when starting a row update (#17732)
1 parent 53fd0e3 commit ee91831

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

packages/x-data-grid-pro/src/tests/rowEditing.DataGridPro.test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,24 @@ describe('<DataGridPro /> - Row editing', () => {
987987
expect(listener.callCount).to.equal(0);
988988
});
989989

990+
it('should call preProcessEditCellProps for editable columns only', async () => {
991+
const preProcessEditCellProps1 = spy(({ props }: GridPreProcessEditCellProps) => props);
992+
const preProcessEditCellProps2 = spy(({ props }: GridPreProcessEditCellProps) => props);
993+
const { user } = render(
994+
<TestCase
995+
column1Props={{ preProcessEditCellProps: preProcessEditCellProps1 }}
996+
column2Props={{ preProcessEditCellProps: preProcessEditCellProps2, editable: false }}
997+
/>,
998+
);
999+
1000+
const cell = getCell(0, 1);
1001+
await user.click(cell);
1002+
await user.keyboard('a');
1003+
1004+
expect(preProcessEditCellProps1.callCount).to.equal(1);
1005+
expect(preProcessEditCellProps2.callCount).to.equal(0);
1006+
});
1007+
9901008
['ctrlKey', 'metaKey'].forEach((key) => {
9911009
it(`should not publish 'rowEditStart' if ${key} is pressed`, () => {
9921010
render(<TestCase />);

packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { gridEditRowsStateSelector, gridRowIsEditingSelector } from './gridEditi
3030
import { GridRowId, GridValidRowModel } from '../../../models/gridRows';
3131
import { isPrintableKey, isPasteShortcut } from '../../../utils/keyboardUtils';
3232
import {
33-
gridColumnFieldsSelector,
33+
gridColumnDefinitionsSelector,
3434
gridVisibleColumnFieldsSelector,
3535
} from '../columns/gridColumnsSelector';
3636
import { GridCellParams } from '../../../models/params/gridCellParams';
@@ -422,9 +422,10 @@ export const useGridRowEditing = (
422422
const { id, fieldToFocus, deleteValue, initialValue } = params;
423423

424424
const row = apiRef.current.getRow(id);
425-
const columnFields = gridColumnFieldsSelector(apiRef);
425+
const columns = gridColumnDefinitionsSelector(apiRef);
426426

427-
const newProps = columnFields.reduce<Record<string, GridEditCellProps>>((acc, field) => {
427+
const newProps = columns.reduce<Record<string, GridEditCellProps>>((acc, col) => {
428+
const field = col.field;
428429
const cellParams = apiRef.current.getCellParams(id, field);
429430
if (!cellParams.isEditable) {
430431
return acc;
@@ -443,7 +444,7 @@ export const useGridRowEditing = (
443444
acc[field] = {
444445
value: newValue,
445446
error: false,
446-
isProcessingProps: !!column.preProcessEditCellProps && deleteValue,
447+
isProcessingProps: column.editable && !!column.preProcessEditCellProps && deleteValue,
447448
};
448449

449450
return acc;
@@ -456,10 +457,10 @@ export const useGridRowEditing = (
456457
apiRef.current.setCellFocus(id, fieldToFocus);
457458
}
458459

459-
columnFields
460-
.filter((field) => !!apiRef.current.getColumn(field).preProcessEditCellProps && deleteValue)
461-
.forEach((field) => {
462-
const column = apiRef.current.getColumn(field);
460+
columns
461+
.filter((column) => column.editable && !!column.preProcessEditCellProps && deleteValue)
462+
.forEach((column) => {
463+
const field = column.field;
463464
const value = apiRef.current.getCellValue(id, field);
464465
const newValue = deleteValue ? getDefaultCellValue(column) : (initialValue ?? value);
465466

0 commit comments

Comments
 (0)