From 4a7b2ac971a8f4e27c2df0d53f90b3eda5483ce9 Mon Sep 17 00:00:00 2001 From: Geoffrey Hervet Date: Fri, 17 May 2024 14:40:48 +0000 Subject: [PATCH] [core] fix remove column pinning position of desired order --- .../src/hooks/features/columns/gridColumnsUtils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/x-data-grid/src/hooks/features/columns/gridColumnsUtils.ts b/packages/x-data-grid/src/hooks/features/columns/gridColumnsUtils.ts index 5727bdf8a821c..74e43c55b82ed 100644 --- a/packages/x-data-grid/src/hooks/features/columns/gridColumnsUtils.ts +++ b/packages/x-data-grid/src/hooks/features/columns/gridColumnsUtils.ts @@ -331,11 +331,18 @@ export const createColumnsState = ({ }; } else { const currentState = gridColumnsStateSelector(apiRef.current.state); + + const pinnedColumns = apiRef.current.state.pinnedColumns; + // Remove pinned columns + const desiredOrderedFields = currentState.orderedFields.filter(field => { + return !(pinnedColumns.left?.includes(field) || pinnedColumns.right?.includes(field)) + }); + columnsState = { orderedFields: keepOnlyColumnsToUpsert ? [] : [...currentState.orderedFields], lookup: { ...currentState.lookup }, // Will be cleaned later if keepOnlyColumnsToUpsert=true columnVisibilityModel, - desiredOrderedFields: currentState.orderedFields, // Will be cleaned later + desiredOrderedFields, // Will be cleaned later }; }