From ab998f7b6dffbe461d830d3696cb46491ad6afb0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Feb 2018 14:36:16 +0100 Subject: Improve admin tables --- client/src/app/shared/rest/rest-table.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'client/src/app/shared/rest/rest-table.ts') 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' import { RestPagination } from './rest-pagination' export abstract class RestTable { + abstract totalRecords: number abstract rowsPerPage: number abstract sort: SortMeta abstract pagination: RestPagination + private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name + protected abstract loadData (): void + loadSort () { + const result = localStorage.getItem(this.sortLocalStorageKey) + + if (result) { + try { + this.sort = JSON.parse(result) + } catch (err) { + console.error('Cannot load sort of local storage key ' + this.sortLocalStorageKey, err) + } + } + } + loadLazy (event: LazyLoadEvent) { this.sort = { order: event.sortOrder, @@ -23,6 +38,11 @@ export abstract class RestTable { } this.loadData() + this.saveSort() + } + + saveSort () { + localStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) } } -- cgit v1.2.3