]>
Commit | Line | Data |
---|---|---|
1 | import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent' | |
2 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
3 | ||
4 | import { RestPagination } from './rest-pagination' | |
5 | ||
6 | export abstract class RestTable { | |
7 | ||
8 | abstract totalRecords: number | |
9 | abstract rowsPerPage: number | |
10 | abstract sort: SortMeta | |
11 | abstract pagination: RestPagination | |
12 | ||
13 | private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name | |
14 | ||
15 | protected abstract loadData (): void | |
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 | ||
29 | loadLazy (event: LazyLoadEvent) { | |
30 | this.sort = { | |
31 | order: event.sortOrder, | |
32 | field: event.sortField | |
33 | } | |
34 | ||
35 | this.pagination = { | |
36 | start: event.first, | |
37 | count: this.rowsPerPage | |
38 | } | |
39 | ||
40 | this.loadData() | |
41 | this.saveSort() | |
42 | } | |
43 | ||
44 | saveSort () { | |
45 | localStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) | |
46 | } | |
47 | ||
48 | } |