Skip to content

Commit

Permalink
save sortingState with tableId
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailn Nifeli Snieske committed Nov 12, 2024
1 parent 6f88ef3 commit 0d87e59
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/beCompliant/src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ export function TableComponent({
] = useColumnVisibility();

const initialSorting: SortingState = JSON.parse(
localStorage.getItem('sortingState') || '[]'
localStorage.getItem(`sortingState_${tableData.id}`) || '[]'
);

const [sorting, setSorting] = useState<SortingState>(initialSorting);

useEffect(() => {
localStorage.setItem('sortingState', JSON.stringify(sorting));
}, [sorting]);
localStorage.setItem(
`sortingState_${tableData.id}`,
JSON.stringify(sorting)
);
}, [sorting, tableData.id]);

const columns: ColumnDef<any, any>[] = tableData.columns.map(
(field, index) => ({
Expand Down

0 comments on commit 0d87e59

Please sign in to comment.