Thanks for the amazing work you've done.
I want to use the paginator but my API doesn't respond with the expected payload described in the documentation:
{
"perPage": 10,
"lastPage": "10",
"currentPage": "3",
"data": [...]
}
Is there a way of prescribing a custom payload response or writing some kind of adapter without having to update the API itself?
Just an idea: maybe you can pipe the request and transform your response format to the expected one
Sample: { pageSize, totalPages, pageNumber, response }
this.pagination$ = this.paginatorRef.pageChanges.pipe(
switchMap(( page ) => {
const req = () => this.contactsService.getPage({
page,
perPage: 10
}).pipe(map(res => ({
perPage: res.pageSize,
lastPage: res.totalPages,
currentPage: res.pageNumber,
data: res.response,
})));
return this.paginator.getPage(req);
})
);
Like @twittwer said. (edited it to add the map operator). Thanks.
Just an idea: maybe you can pipe the request and transform your response format to the expected one
Sample:{ pageSize, totalPages, pageNumber, response }this.pagination$ = this.paginatorRef.pageChanges.pipe( switchMap(( page ) => { const req = () => this.contactsService.getPage({ page, perPage: 10 }).pipe(map(res => ({ perPage: res.pageSize, lastPage: res.totalPages, currentPage: res.pageNumber, data: res.response, }))); return this.paginator.getPage(req); }) );
hi @NetanelBasal
While using NgEntityService, How to avoid to save the whole response including pagination meta in the store?
Ok get it. by using conf.skipWrite.
Most helpful comment
Like @twittwer said. (edited it to add the map operator). Thanks.