Created
August 24, 2022 04:33
-
-
Save touhidrahman/f8be2ffd5fc878931fc12d0aa3e66e39 to your computer and use it in GitHub Desktop.
Paginator full
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
<nav aria-label="Page navigation"> | |
<ul class="navlinks"> | |
<li *ngIf="showFirstLastButton"> | |
<a | |
[queryParams]="{ size: size, page: 1 }" | |
[routerLink]="routerLinkBase" | |
queryParamsHandling="merge" | |
class="navlink" | |
> | |
First | |
</a> | |
</li> | |
<li> | |
<a | |
[queryParams]="{ size: size, page: currentPage - 1 }" | |
[routerLink]="routerLinkBase" | |
queryParamsHandling="merge" | |
class="navlink" | |
> | |
< Prev | |
</a> | |
</li> | |
<li *ngFor="let page of getNavigablePages()"> | |
<a | |
[queryParams]="{ size: size, page: page }" | |
[routerLink]="routerLinkBase" | |
queryParamsHandling="merge" | |
[class.active]="page === currentPage" | |
class="navlink" | |
> | |
{{ page }} | |
</a> | |
</li> | |
<li> | |
<a | |
[queryParams]="{ size: size, page: currentPage + 1 }" | |
[routerLink]="routerLinkBase" | |
queryParamsHandling="merge" | |
class="navlink" | |
> | |
Next > | |
</a> | |
</li> | |
<li *ngIf="showFirstLastButton"> | |
<a | |
[queryParams]="{ size: size, page: totalPages }" | |
[routerLink]="routerLinkBase" | |
queryParamsHandling="merge" | |
class="navlink" | |
> | |
Last | |
</a> | |
</li> | |
</ul> | |
</nav> |
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
:host { | |
display: block; | |
} | |
.navlinks { | |
display: inline-flex; | |
} | |
.navlinks li { | |
margin-right: 0; | |
margin-left: -1px; | |
&:first-child .navlink { | |
border-top-left-radius: 0.5rem; | |
border-bottom-left-radius: 0.5rem; | |
} | |
&:last-child .navlink { | |
border-top-right-radius: 0.5rem; | |
border-bottom-right-radius: 0.5rem; | |
} | |
} | |
.navlink { | |
margin-left: 0; | |
border-width: 1px; | |
border-color: rgb(209 213 219); | |
background-color: white; | |
padding: 0.5rem 0.75rem; | |
line-height: 1.25; | |
color: rgb(107 114 128); | |
&:hover { | |
background-color: rgb(243 244 246); | |
color: rgb(55 65 81); | |
} | |
&.active { | |
background-color: rgb(220, 222, 226); | |
color: rgb(55 65 81); | |
} | |
} |
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
import { CommonModule } from '@angular/common' | |
import { ChangeDetectionStrategy, Component, Input } from '@angular/core' | |
import { RouterModule } from '@angular/router' | |
@Component({ | |
selector: 'app-pagination', | |
standalone: true, | |
imports: [CommonModule, RouterModule], | |
templateUrl: './pagination.component.html', | |
styleUrls: ['./pagination.component.scss'], | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
}) | |
export class PaginationComponent { | |
@Input() currentPage = 1 | |
@Input() totalPages = 1 | |
@Input() size = 24 | |
@Input() windowSize = 2 | |
@Input() showFirstLastButton = true | |
@Input() routerLinkBase: string[] = [] | |
getNavigablePages(): number[] { | |
const pages = [] | |
const left = Math.max(1, this.currentPage - this.windowSize) | |
const right = Math.min(this.totalPages, this.currentPage + this.windowSize) | |
for (let i = left; i <= right; i++) { | |
pages.push(i) | |
} | |
return pages | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment