Fix empty filters saving to hash
This commit is contained in:
@@ -18,18 +18,18 @@ export function useInitialTableState(tableId: string): TableState {
|
|||||||
const savedSorters = hasHashProperty("sorters")
|
const savedSorters = hasHashProperty("sorters")
|
||||||
? getHashProperty("sorters")
|
? getHashProperty("sorters")
|
||||||
: isLocalStorageAvailable
|
: isLocalStorageAvailable
|
||||||
? localStorage.getItem(`${tableId}-sorters`)
|
? localStorage.getItem(`${tableId}-sorters`)
|
||||||
: null;
|
: null;
|
||||||
const savedFilters = hasHashProperty("filters")
|
const savedFilters = hasHashProperty("filters")
|
||||||
? getHashProperty("filters")
|
? getHashProperty("filters")
|
||||||
: isLocalStorageAvailable
|
: isLocalStorageAvailable
|
||||||
? localStorage.getItem(`${tableId}-filters`)
|
? localStorage.getItem(`${tableId}-filters`)
|
||||||
: null;
|
: null;
|
||||||
const savedPagination = hasHashProperty("pagination")
|
const savedPagination = hasHashProperty("pagination")
|
||||||
? getHashProperty("pagination")
|
? getHashProperty("pagination")
|
||||||
: isLocalStorageAvailable
|
: isLocalStorageAvailable
|
||||||
? localStorage.getItem(`${tableId}-pagination`)
|
? localStorage.getItem(`${tableId}-pagination`)
|
||||||
: null;
|
: null;
|
||||||
const savedShowColumns = isLocalStorageAvailable ? localStorage.getItem(`${tableId}-showColumns`) : null;
|
const savedShowColumns = isLocalStorageAvailable ? localStorage.getItem(`${tableId}-showColumns`) : null;
|
||||||
|
|
||||||
const sorters = savedSorters ? JSON.parse(savedSorters) : [{ field: "id", order: "asc" }];
|
const sorters = savedSorters ? JSON.parse(savedSorters) : [{ field: "id", order: "asc" }];
|
||||||
@@ -59,7 +59,7 @@ export function useStoreInitialState(tableId: string, state: TableState) {
|
|||||||
if (filters.length > 0) {
|
if (filters.length > 0) {
|
||||||
if (isLocalStorageAvailable) {
|
if (isLocalStorageAvailable) {
|
||||||
localStorage.setItem(`${tableId}-filters`, JSON.stringify(filters));
|
localStorage.setItem(`${tableId}-filters`, JSON.stringify(filters));
|
||||||
setURLHash("filters", JSON.stringify(state.filters));
|
setURLHash("filters", JSON.stringify(filters));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(`${tableId}-filters`);
|
localStorage.removeItem(`${tableId}-filters`);
|
||||||
|
|||||||
Reference in New Issue
Block a user