I have a total of 250
items and I'm displaying 5
of them i.e. pageSize
is set to 5.
and I've set the paginator.length
property to items.length
Now, there are two problems here:
Even though I've manually set the paginator.length
but when I console.log
the properties of paginator, it shows 5
(Which is the number of items I'm displaying per page). hence the next
button of paginator is disabled.
How do I enable the next
button, so that when it is clicked I would know and request the next data to server.
Remember: I'm using only back-end pagination for this regard.
Pagination information is passed in response headers from the server.
Here is my code
pageIndex=1;
pageNumber;
pagination;
ngOnInit(): void {
this.paginator.pageSize = 5;
this.paginator.pageIndex = this.pageIndex;
this.salesReportService.getDailyReport().subscribe((response) => {
console.log('Response of sales report : ', response);
this.reports = response.body;
this.pagination=response.headers.get('X-Pagination');
console.log('PaginationInformation: ',this.pagination)
this.paginator.length=this.pagination.TotalCount;
console.log('paginator properties: ', this.paginator);
console.log('paginator hasNextpage(): ', this.paginator.hasNextPage());
this.dataSource = new MatTableDataSource(this.reports);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}, (error) => {
console.log('Error occured while fetching sales report: ', error);
});
}
// here I'd call the function to get the next data when the next button of paginator is clicked.
// something like this
this.salesReportService.getReports(pageNumber:2)