From 571b46c9ff38ebe6ddc9223a2d2f74ec7bea1181 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 29 Mar 2026 15:21:53 +1100 Subject: [PATCH] Fix order of hooks for stabilizing table columns (#11482) * Fix order of hooks for stabilizing table columns Ref: https://github.com/icflorescu/mantine-datatable/issues/759 * Reset column ordering and widths when the component is mounted --------- Co-authored-by: Matthias Mair --- src/frontend/src/tables/InvenTreeTable.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/tables/InvenTreeTable.tsx b/src/frontend/src/tables/InvenTreeTable.tsx index 65cff57c19..d290eafb48 100644 --- a/src/frontend/src/tables/InvenTreeTable.tsx +++ b/src/frontend/src/tables/InvenTreeTable.tsx @@ -333,9 +333,6 @@ export function InvenTreeTable>({ }); } - const columnNames: string = cols.map((col) => col.accessor).join(','); - setColumnHash(hashString(columnNames)); - return cols; }, [ columns, @@ -345,6 +342,13 @@ export function InvenTreeTable>({ tableState.selectedRecords ]); + useEffect(() => { + const columnNames: string = dataColumns + .map((col: any) => col.accessor) + .join(','); + setColumnHash(hashString(columnNames)); + }, [dataColumns]); + // Callback when column visibility is toggled const toggleColumn = useCallback( (columnName: string) => { @@ -373,6 +377,13 @@ export function InvenTreeTable>({ getInitialValueInEffect: false }); + // Reset column ordering and custom widths when the component is mounted + // Ref: https://github.com/icflorescu/mantine-datatable/issues/759#issuecomment-4148942070 + useEffect(() => { + tableColumns.resetColumnsOrder(); + tableColumns.resetColumnsWidth(); + }, []); + // Reset the pagination state when the search term changes useEffect(() => { tableState.setPage(1);