Search code examples
angulartypescriptng2-smart-table

Last page number (Server side pagination, Ng2-Smart-Table)


I'm using Ng2-Smart-Table component with server side pagination. I tested the example (https://github.com/akveo/ng2-smart-table/blob/master/src/app/pages/examples/server/advanced-example-server.component.ts)

Analyzing the requests from the above examples, I noticed that no response comes from anything other than JSON records / objects: IMAGE - Response Example.

DOUBT: How does the component know which is the last page? (In example 500): IMAGE - Example last page pagination

I'm trying to understand to implement in my API, because I'll implement a bit different from the example, requesting only in the service. So I want to know how the component get the value of the last page.


Solution

  • I found the answer to my own question XD After debugging the component code in the server.data-source.js file I discovered how the component does, it does two validations and can extract the total of lines by two ways. First it validates the response header if there is a Key equal to the value placed in the Key totalKey of the instance of the ServerDataSource object in your aplication angular.

    If it does not exist it looks in the list of JSON objects of the response, also by the same key.