From cf16935b9d2bdb6220090586b5d0f59af8c916af Mon Sep 17 00:00:00 2001 From: Marco Schumacher Date: Fri, 2 Sep 2022 22:57:14 +0200 Subject: [PATCH] fix: don't persist controlled values --- src/internalState/tableStateStorage.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/internalState/tableStateStorage.ts b/src/internalState/tableStateStorage.ts index c3d3ef8..8dd0d47 100644 --- a/src/internalState/tableStateStorage.ts +++ b/src/internalState/tableStateStorage.ts @@ -100,16 +100,20 @@ export function useTableStateStorage(table: Store>) { ) { if (key === 'filterValues') { for (const [id, value] of data[key]) { - if (state.filters.get(id)?.persist ?? true) { + if (state.filters.get(id)?.persist ?? state.filters.get(id)?.value === undefined) { state.filterValues.set(id, value); } } } else { - state[key] = data[key]; - if (key === 'expanded' || key === 'hiddenColumns' || key === 'selection' || key === 'sort') { + if (state.props[key] !== undefined) { + continue; + } + state.props[`on${(key.slice(0, 1).toUpperCase() + key.slice(1)) as Capitalize}Change`]?.(data[key]); } + + state[key] = data[key]; } } } @@ -146,11 +150,20 @@ export function useTableStateStorage(table: Store>) { if (key === 'filterValues') { data[key] = new Map(); for (const [id, value] of state.filterValues) { - if (state.filters.get(id)?.persist ?? true) { + if (state.filters.get(id)?.persist ?? state.filters.get(id)?.value === undefined) { data.filterValues.set(id, value); } } } else { + if ( + key === 'expanded' || + key === 'hiddenColumns' || + key === 'selection' || + (key === 'sort' && state.props[key] !== undefined) + ) { + continue; + } + data[key] = state[key]; } }