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 -->
|
<!-- 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">
|
<ul class="pagination pagination-sm">
|
||||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- 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">
|
<ul class="pagination pagination-sm">
|
||||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ export class LibraryComponent {
|
|||||||
constructor(private libraryService: LibraryService) {}
|
constructor(private libraryService: LibraryService) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.entriesCount = this.entries.length;
|
|
||||||
this.maxPage = this.entriesCount / this.pageSize;
|
|
||||||
this.pageSize = this.getDefaultPageSize();
|
this.pageSize = this.getDefaultPageSize();
|
||||||
this.fetchEntries();
|
this.fetchEntries();
|
||||||
}
|
}
|
||||||
@@ -52,23 +50,12 @@ export class LibraryComponent {
|
|||||||
} else {
|
} else {
|
||||||
temp = this.entries;
|
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 startIndex = (this.currentPage - 1) * this.pageSize;
|
||||||
const endIndex = startIndex + this.pageSize;
|
const endIndex = startIndex + this.pageSize;
|
||||||
|
|
||||||
this.entriesCount = this.entriesToShow.length;
|
this.entriesCount = temp.length;
|
||||||
this.maxPage = this.entriesCount / this.pageSize;
|
this.maxPage = Math.ceil(this.entriesCount / this.pageSize);
|
||||||
this.entriesToShow = [];
|
|
||||||
this.entriesToShow = temp.slice(startIndex, endIndex);
|
this.entriesToShow = temp.slice(startIndex, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,21 +66,13 @@ export class LibraryComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get pageNumbers(): number[] {
|
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 pagesToShow = 5; // Total pages to show at any time
|
||||||
let startPage: number, endPage: number;
|
let startPage: number, endPage: number;
|
||||||
|
|
||||||
if (this.maxPage <= pagesToShow) {
|
if (this.maxPage <= pagesToShow) {
|
||||||
// Case when the total number of pages is less or equal to pagesToShow.
|
|
||||||
startPage = 1;
|
startPage = 1;
|
||||||
endPage = this.maxPage;
|
endPage = this.maxPage;
|
||||||
} else {
|
} else {
|
||||||
// Calculate the start page.
|
|
||||||
startPage = Math.max(this.currentPage - Math.floor(pagesToShow / 2), 1);
|
startPage = Math.max(this.currentPage - Math.floor(pagesToShow / 2), 1);
|
||||||
endPage = startPage + pagesToShow - 1;
|
endPage = startPage + pagesToShow - 1;
|
||||||
|
|
||||||
@@ -114,12 +93,13 @@ export class LibraryComponent {
|
|||||||
setEntryType(entryType: number) {
|
setEntryType(entryType: number) {
|
||||||
this.entryType = entryType;
|
this.entryType = entryType;
|
||||||
this.currentPage = 1;
|
this.currentPage = 1;
|
||||||
|
|
||||||
this.filterEntries();
|
this.filterEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
setPageSize(event: any) {
|
setPageSize(event: any) {
|
||||||
this.pageSize = event.target.value;
|
this.pageSize = event.target.value;
|
||||||
this.filterEntries()
|
this.filterEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultPageSize() {
|
getDefaultPageSize() {
|
||||||
|
|||||||
Reference in new issue
Block a user