fix library pagination
This commit is contained in:
1 parent
b8e8a9a581
commit
de39e469b7
2 files changed
+6
-26
No files matched your search
@@ -38,7 +38,7 @@
|
||||
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1">
|
||||
<ul class="pagination pagination-sm">
|
||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1">
|
||||
<ul class="pagination pagination-sm">
|
||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||
|
||||
@@ -21,8 +21,6 @@ export class LibraryComponent {
|
||||
constructor(private libraryService: LibraryService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.entriesCount = this.entries.length;
|
||||
this.maxPage = this.entriesCount / this.pageSize;
|
||||
this.pageSize = this.getDefaultPageSize();
|
||||
this.fetchEntries();
|
||||
}
|
||||
@@ -52,23 +50,12 @@ export class LibraryComponent {
|
||||
} else {
|
||||
temp = this.entries;
|
||||
}
|
||||
console.log(temp);
|
||||
|
||||
// ? title search
|
||||
// let len = temp.length;
|
||||
// for (let i = 0; i < len; i++) {
|
||||
// if (!temp[i].title.toLocaleLowerCase().includes('od')) {
|
||||
// temp.splice(i);
|
||||
// len--;
|
||||
// }
|
||||
// }
|
||||
|
||||
const startIndex = (this.currentPage - 1) * this.pageSize;
|
||||
const endIndex = startIndex + this.pageSize;
|
||||
|
||||
this.entriesCount = this.entriesToShow.length;
|
||||
this.maxPage = this.entriesCount / this.pageSize;
|
||||
this.entriesToShow = [];
|
||||
this.entriesCount = temp.length;
|
||||
this.maxPage = Math.ceil(this.entriesCount / this.pageSize);
|
||||
this.entriesToShow = temp.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
@@ -79,21 +66,13 @@ export class LibraryComponent {
|
||||
}
|
||||
|
||||
get pageNumbers(): number[] {
|
||||
this.entriesCount = this.entries.length;
|
||||
this.maxPage = this.entriesCount / this.pageSize;
|
||||
|
||||
// Ensure currentPage is within the bounds.
|
||||
this.currentPage = Math.max(1, Math.min(this.currentPage, this.maxPage));
|
||||
|
||||
let pagesToShow = 5; // Total pages to show at any time
|
||||
let startPage: number, endPage: number;
|
||||
|
||||
if (this.maxPage <= pagesToShow) {
|
||||
// Case when the total number of pages is less or equal to pagesToShow.
|
||||
startPage = 1;
|
||||
endPage = this.maxPage;
|
||||
} else {
|
||||
// Calculate the start page.
|
||||
startPage = Math.max(this.currentPage - Math.floor(pagesToShow / 2), 1);
|
||||
endPage = startPage + pagesToShow - 1;
|
||||
|
||||
@@ -114,12 +93,13 @@ export class LibraryComponent {
|
||||
setEntryType(entryType: number) {
|
||||
this.entryType = entryType;
|
||||
this.currentPage = 1;
|
||||
|
||||
this.filterEntries();
|
||||
}
|
||||
|
||||
setPageSize(event: any) {
|
||||
this.pageSize = event.target.value;
|
||||
this.filterEntries()
|
||||
this.filterEntries();
|
||||
}
|
||||
|
||||
getDefaultPageSize() {
|
||||
|
||||
Reference in new issue
Block a user