angular-material-course
angular-material-course copied to clipboard
Pagination from serverside not working
Please update code for paginator correct working...
loadLessons(courseId:number,
filter:string,
sortDirection:string,
pageIndex:number,
pageSize:number) {
this.loadingSubject.next(true);
this.coursesService.findLessons(courseId, filter, sortDirection,
pageIndex, pageSize).pipe(
catchError(() => of([])),
finalize(() => this.loadingSubject.next(false))
)
.subscribe((lessonList: LessionList) => {
this.lessonsSubject.next(lessonList.payload)
this._updatePaginator(lessonsList.total)
});
}
get paginator(): MatPaginator | null { return this._paginator; }
set paginator(paginator: MatPaginator|null) {
this._paginator = paginator;
//this._updateChangeSubscription();
}
private _paginator: MatPaginator|null;
_updatePaginator(filteredDataLength: number) {
Promise.resolve().then(() => {
if (!this.paginator) { return; }
this.paginator.length = filteredDataLength;
// If the page index is set beyond the page, reduce it to the last page.
if (this.paginator.pageIndex > 0) {
const lastPageIndex = Math.ceil(this.paginator.length / this.paginator.pageSize) - 1 || 0;
this.paginator.pageIndex = Math.min(this.paginator.pageIndex, lastPageIndex);
}
});
}
then update server side and CoursesService
to get LessionList
from server.
LessionList {
payload: lession[];
total: number
}
and then insert this line after dataSource
initialization in CourseComponent
:
this.dataSource.paginator = this.paginator;
This implementation work correctly.
you can do it yourself, propose a project modification. and fix your "lession" vs "lesson"