diff --git a/src/frontend/src/states/LocalState.tsx b/src/frontend/src/states/LocalState.tsx index 39d75fc0f3..dafa7b6ad8 100644 --- a/src/frontend/src/states/LocalState.tsx +++ b/src/frontend/src/states/LocalState.tsx @@ -1,3 +1,4 @@ +import { DataTableSortStatus } from 'mantine-datatable'; import { create } from 'zustand'; import { persist } from 'zustand/middleware'; @@ -28,6 +29,9 @@ interface LocalStateProps { setTableColumnNames: ( tableKey: string ) => (names: Record) => void; + tableSorting: Record; + getTableSorting: (tableKey: string) => DataTableSortStatus; + setTableSorting: (tableKey: string) => (sorting: DataTableSortStatus) => void; clearTableColumnNames: () => void; detailDrawerStack: number; addDetailDrawer: (value: number | false) => void; @@ -87,6 +91,19 @@ export const useLocalState = create()( clearTableColumnNames: () => { set({ tableColumnNames: {} }); }, + tableSorting: {}, + getTableSorting: (tableKey) => { + return get().tableSorting[tableKey] || {}; + }, + setTableSorting: (tableKey) => (sorting) => { + // Update the table sorting for the given table + set({ + tableSorting: { + ...get().tableSorting, + [tableKey]: sorting + } + }); + }, // detail drawers detailDrawerStack: 0, addDetailDrawer: (value) => { diff --git a/src/frontend/src/tables/InvenTreeTable.tsx b/src/frontend/src/tables/InvenTreeTable.tsx index 2090d27bab..a33cb4da01 100644 --- a/src/frontend/src/tables/InvenTreeTable.tsx +++ b/src/frontend/src/tables/InvenTreeTable.tsx @@ -10,8 +10,6 @@ import { Stack, Tooltip } from '@mantine/core'; -import { modals } from '@mantine/modals'; -import { showNotification } from '@mantine/notifications'; import { IconBarcode, IconFilter, @@ -157,7 +155,12 @@ export function InvenTreeTable({ columns: TableColumn[]; props: InvenTreeTableProps; }) { - const { getTableColumnNames, setTableColumnNames } = useLocalState(); + const { + getTableColumnNames, + setTableColumnNames, + getTableSorting, + setTableSorting + } = useLocalState(); const [fieldNames, setFieldNames] = useState>({}); const navigate = useNavigate(); @@ -390,6 +393,15 @@ export function InvenTreeTable({ direction: 'asc' }); + useEffect(() => { + const tableKey: string = tableState.tableKey.split('-')[0]; + const sorting: DataTableSortStatus = getTableSorting(tableKey); + + if (sorting) { + setSortStatus(sorting); + } + }, []); + // Return the ordering parameter function getOrderingTerm() { let key = sortStatus.columnAccessor; @@ -413,6 +425,9 @@ export function InvenTreeTable({ const handleSortStatusChange = (status: DataTableSortStatus) => { tableState.setPage(1); setSortStatus(status); + + const tableKey = tableState.tableKey.split('-')[0]; + setTableSorting(tableKey)(status); }; // Function to perform API query to fetch required data