-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
Bug, feature request, or proposal:
I'm trying to implement HTTP pagination as exemplified on documents with my own API.
The problem is that the total items count (length) is being set incorrectly!
My code follows exactly the same thing of the example.
What is the expected behavior?
It should just respect the value that I set. On my code, I use my API response (total) to set the paginators length, just as on the docs example.
What is the current behavior?
Looks like the length "blinks" from the total given by API to the current page length.
For example, if I load a resource that have a total of 9 items, and the page size is 5,
imediatelly after it load, I can see (very fast) the total of 9, with the next button enabled, then
it goes to 5 (the page length, not the total).
If in the same same, I set page size to 10, it shows the total of 9 (right, because the page 1 have exactly 9).
Looks like this is a behavior from non http pagination, where it try to paginate from the entire dataset.
What are the steps to reproduce?
Cannot provide a plunker right now, but the relevant code is:
ngAfterViewInit() {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
merge(this.sort.sortChange, this.paginator.page)
.pipe(
startWith({}),
switchMap(() => {
this.isLoadingResults = true;
return this.modelProvider.list({page: this.paginator.pageIndex + 1, size: this.paginator.pageSize});
}),
map((collection: Collection<any>) => {
this.isLoadingResults = false;
this.resultsLength = collection.meta.total;
return collection.data;
}),
catchError(() => {
this.isLoadingResults = false;
return observableOf([]);
})
).subscribe(data => this.dataSource.data = data );
}
ngAfterViewInit() {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
merge(this.sort.sortChange, this.paginator.page)
.pipe(
startWith({}),
switchMap(() => {
this.isLoadingResults = true;
return this.modelProvider.list({page: this.paginator.pageIndex + 1, size: this.paginator.pageSize});
}),
map((collection: Collection<any>) => {
this.isLoadingResults = false;
this.resultsLength = collection.meta.total;
return collection.data;
}),
catchError(() => {
this.isLoadingResults = false;
return observableOf([]);
})
).subscribe(data => this.dataSource.data = data );
}
And my paginator on view is defined:
<mat-paginator #paginator
[length]="resultsLength"
[pageSize]="5"
[pageSizeOptions]="[5, 10, 20]"
*ngIf="paginate">
</mat-paginator>
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
The latest available versions, I've just installed everything.