-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save pageSize setting into sessionStorage (#1207)
Add attribute directive to mat-paginator The selected items per page setting for each issue table is lost after navigation to a different page or on refresh. Caching this setting is more user-friendly because users do not need to re-input the same page settings. Let's save this setting to session storage using an attribute directive.
- Loading branch information
Showing
13 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/app/core/directives/paginator-local-storage.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Directive, Input, OnInit } from '@angular/core'; | ||
import { MatPaginator, PageEvent } from '@angular/material/paginator'; | ||
|
||
@Directive({ | ||
selector: '[paginatorLocalStorage]' | ||
}) | ||
export class PaginatorLocalStorageDirective implements OnInit { | ||
private element: MatPaginator; | ||
private key: string; | ||
|
||
@Input() paginatorLocalStorage: string; | ||
|
||
get pageSize() { | ||
const cachedPageSize = sessionStorage.getItem(this.key) || this.element.pageSize; | ||
return Number(cachedPageSize); | ||
} | ||
|
||
set pageSize(num: number) { | ||
const pageSizeToCache = String(num); | ||
sessionStorage.setItem(this.key, pageSizeToCache); | ||
} | ||
|
||
constructor(private el: MatPaginator) { | ||
this.element = el; | ||
} | ||
|
||
ngOnInit(): void { | ||
this.key = this.paginatorLocalStorage + '-PageSize'; | ||
this.element.pageSize = this.pageSize; | ||
this.element.page.subscribe((page: PageEvent) => { | ||
this.pageSize = page.pageSize; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
import { PaginatorLocalStorageDirective } from '../../core/directives/paginator-local-storage.directive'; | ||
import { MaterialModule } from '../material.module'; | ||
import { IssueTablesComponent } from './issue-tables.component'; | ||
|
||
@NgModule({ | ||
exports: [IssueTablesComponent], | ||
declarations: [IssueTablesComponent], | ||
declarations: [IssueTablesComponent, PaginatorLocalStorageDirective], | ||
imports: [CommonModule, MaterialModule, RouterModule] | ||
}) | ||
export class IssueTablesModule {} |