Skip to content

Commit

Permalink
Merge pull request #747 from rocket-admin/backurl-sessionstorage
Browse files Browse the repository at this point in the history
save back url and filters in session storage
  • Loading branch information
lyubov-voloshko authored Jul 22, 2024
2 parents 6bee9a5 + b039edb commit f92c68d
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions frontend/src/app/services/table-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,46 @@ export class TableStateService {
private selectedRowSubject = new BehaviorSubject<any>(null);
cast = this.selectedRowSubject.asObservable();

private backUrlFilters: any;
private backUrlParams: any;
// private backUrlFilters: any;
// private backUrlParams: any;

setBackUrlParams(pageIndex, pageSize, sortField, sortDirection) {
this.backUrlParams = {
private getSessionStorageItem(key: string) {
const item = sessionStorage.getItem(key);
if (item) {
try {
return JSON.parse(item);
} catch (e) {
console.error(`Error parsing JSON from sessionStorage for key "${key}":`, e);
return null;
}
}
return null;
}

private setSessionStorageItem(key: string, value: any) {
sessionStorage.setItem(key, JSON.stringify(value));
}

setBackUrlParams(pageIndex: number, pageSize: number, sortField: string, sortDirection: string) {
const params = {
page_index: pageIndex,
page_size: pageSize,
sort_active: sortField,
sort_direction: sortDirection
};
this.setSessionStorageItem('backUrlParams', params);
}

getBackUrlParams() {
return this.backUrlParams;
return this.getSessionStorageItem('backUrlParams');
}

setBackUrlFilters(filters: any) {
this.backUrlFilters = filters;
this.setSessionStorageItem('backUrlFilters', filters);
}

getBackUrlFilters() {
return this.backUrlFilters;
return this.getSessionStorageItem('backUrlFilters');
}

selectRow(row: TableRow) {
Expand Down

0 comments on commit f92c68d

Please sign in to comment.