Akita: Custom pagination interface?

Created on 12 Feb 2019  路  4Comments  路  Source: datorama/akita

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?

help wanted

Most helpful comment

Like @twittwer said. (edited it to add the map operator). Thanks.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings