diff options
Diffstat (limited to 'client/src/app/shared/rest')
-rw-r--r-- | client/src/app/shared/rest/rest-table.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/client/src/app/shared/rest/rest-table.ts b/client/src/app/shared/rest/rest-table.ts index d04d91c68..165fc4e45 100644 --- a/client/src/app/shared/rest/rest-table.ts +++ b/client/src/app/shared/rest/rest-table.ts | |||
@@ -4,13 +4,28 @@ import { SortMeta } from 'primeng/components/common/sortmeta' | |||
4 | import { RestPagination } from './rest-pagination' | 4 | import { RestPagination } from './rest-pagination' |
5 | 5 | ||
6 | export abstract class RestTable { | 6 | export abstract class RestTable { |
7 | |||
7 | abstract totalRecords: number | 8 | abstract totalRecords: number |
8 | abstract rowsPerPage: number | 9 | abstract rowsPerPage: number |
9 | abstract sort: SortMeta | 10 | abstract sort: SortMeta |
10 | abstract pagination: RestPagination | 11 | abstract pagination: RestPagination |
11 | 12 | ||
13 | private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name | ||
14 | |||
12 | protected abstract loadData (): void | 15 | protected abstract loadData (): void |
13 | 16 | ||
17 | loadSort () { | ||
18 | const result = localStorage.getItem(this.sortLocalStorageKey) | ||
19 | |||
20 | if (result) { | ||
21 | try { | ||
22 | this.sort = JSON.parse(result) | ||
23 | } catch (err) { | ||
24 | console.error('Cannot load sort of local storage key ' + this.sortLocalStorageKey, err) | ||
25 | } | ||
26 | } | ||
27 | } | ||
28 | |||
14 | loadLazy (event: LazyLoadEvent) { | 29 | loadLazy (event: LazyLoadEvent) { |
15 | this.sort = { | 30 | this.sort = { |
16 | order: event.sortOrder, | 31 | order: event.sortOrder, |
@@ -23,6 +38,11 @@ export abstract class RestTable { | |||
23 | } | 38 | } |
24 | 39 | ||
25 | this.loadData() | 40 | this.loadData() |
41 | this.saveSort() | ||
42 | } | ||
43 | |||
44 | saveSort () { | ||
45 | localStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) | ||
26 | } | 46 | } |
27 | 47 | ||
28 | } | 48 | } |