Pagination updates
This commit is contained in:
parent
292573f3b3
commit
d67798bd60
@ -4,6 +4,7 @@ import { EntitiesService } from './entities.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { mapEach } from '../../utils';
|
||||
import { PaginationSettings } from '../../pagination';
|
||||
|
||||
interface PaginatedResponse<Interface> {
|
||||
data: Interface[];
|
||||
@ -48,6 +49,13 @@ export abstract class PaginatedEntitiesService<
|
||||
return this._currentConfig;
|
||||
}
|
||||
|
||||
get paginationSettings(): PaginationSettings {
|
||||
return {
|
||||
currentPage: this.config.page || 0,
|
||||
totalPages: Math.ceil(this._currentConfig.totalHits / this._currentConfig.pageSize),
|
||||
};
|
||||
}
|
||||
|
||||
updateSearchQueryAndReload(value: string): Observable<Class[]> {
|
||||
return this.loadPage(0, this._currentConfig.pageSize, { [this._searchKey]: value } as SearchOptions);
|
||||
}
|
||||
|
||||
2
src/lib/pagination/index.ts
Normal file
2
src/lib/pagination/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './pagination-settings';
|
||||
export * from './pagination.component';
|
||||
4
src/lib/pagination/pagination-settings.ts
Normal file
4
src/lib/pagination/pagination-settings.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface PaginationSettings {
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
}
|
||||
@ -20,7 +20,7 @@
|
||||
<div
|
||||
id="pagination-next-page-btn"
|
||||
(click)="selectPage(currentPage + 1)"
|
||||
[class.disabled]="currentPage === totalPages - 1"
|
||||
[class.disabled]="currentPage >= totalPages - 1"
|
||||
class="page"
|
||||
translate="pagination.next"
|
||||
></div>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { NgForOf } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { PaginationSettings } from './pagination-settings';
|
||||
|
||||
@Component({
|
||||
selector: 'iqser-pagination',
|
||||
@ -27,7 +28,7 @@ export class PaginationComponent {
|
||||
}
|
||||
|
||||
@Input()
|
||||
set settings(value: { currentPage: number; totalPages: number }) {
|
||||
set settings(value: PaginationSettings) {
|
||||
this._currentPage = value.currentPage;
|
||||
this._totalPages = value.totalPages;
|
||||
this._updatePagesArray();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user