2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-30 16:11:04 +00:00

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 <code@mjmair.com>
This commit is contained in:
Oliver
2026-03-29 15:21:53 +11:00
committed by GitHub
parent 9cd0b520c2
commit 571b46c9ff

View File

@@ -333,9 +333,6 @@ export function InvenTreeTable<T extends Record<string, any>>({
});
}
const columnNames: string = cols.map((col) => col.accessor).join(',');
setColumnHash(hashString(columnNames));
return cols;
}, [
columns,
@@ -345,6 +342,13 @@ export function InvenTreeTable<T extends Record<string, any>>({
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<T extends Record<string, any>>({
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);