96
Views
9
Comments
Pagination with Rest API.
Question

Hi I am displaying data in the table from REST API. API supports pagination.

{
    "pageNumber": 1,
    "pageSize": 10,
    "prevPage": null,
    "nextPage": 2,
    "maxPage": 5,
    "itemType": "",
    "pageItems": 10,
    "totalItems": 47,

}

I was able to successfully implement the pagination. It's working perfectly fine beside one thing. Sometimes when I refresh the page I get "Cannot assign a JavaScript number with value NaN to an output parameter of type Integer Check the JavaScript node 'GetToltalPages' of the action 'InitPagination".

Please help me with this Issue.

Thank you for your time. :)


Staff
Rank: #4993

Hey Nannu, can you share a screenshot, especially the REST API you are using. Is this an external API that you built a library around?

Are you building in Traditional Web or Reactive Web? 

Hi Nannu,

Good morning!

Can you please ellaborate further?

My I assumption for now is why not convert the JSON result to a RecordList so it can be paginated smoothly.

Thank you and kind regards,

Chris

mvp_badge
MVP
Rank: #131

Hello Nanu,

You are passing NaN (Null value) to an Integer output parameter in your javascript code (inside action InitPagination). So you got that error.

Can you please share your Javascript code that you have in action InitPagination? Focus when you call 'GetToltalPages' please.


BR,

Luis

Rank: #1604

Thank you all for your reply.

1. I am using reactive app and it's an external API.

2. I am actually assigning values to the pagination variables from my API structure(Because API supports pagination). And pagination is working perfectly fine.

.3. I didn't right any JavaScript code. Action InitPagination is a part of pagination component. It's under outsystemsUI > Pagination > InitPagination.


Thank you.

Looking forward to your reply.

mvp_badge
MVP
Rank: #131

Hi Nannu 

Can you confirm if you are setting all the correct values as is described in documentation?

Can you validate if you are not passing 0 in TotalCount?


BR,

Luis

Rank: #1604

Luís Cardoso wrote:

Hi Nannu 

Can you confirm if you are setting all the correct values as is described in documentation?

Can you validate if you are not passing 0 in TotalCount?


BR,

Luis

Hi Luis,

I am assigning TotalCount = 

GetAllSecurityRoleMembers.Out1.Payload.TotalItems

and my API  response is:

"payload": {
    "pageNumber": 1,
    "pageSize": 10,
    "prevPage": null,
    "nextPage": null,
    "maxPage": 1,
    "itemType": "Sec",
    "pageItems": 5,
    "totalItems": 5

}


Also I am getting right count in the pagination just don't how can I debug this issue.

Thank you for your time. I really appreciate it.

Rank: #2927

I know this is very late, but I don't see the answer that I managed to figure out.

It looks like the code in the Pagination widget does not check for zero values in MaxRecords, and that is where the error comes in. I encountered this problem doing an exercise in the Reactive Web Developer course.

The workaround is to make sure that you never pass a zero value to Pagination.MaxRecords. In the exercise, I created an Input field, set it to use an integer called MyMaxRecords, and set the Pagination widget to use MyMaxRecords. I got this error whenever I backspaced over the value in the Input field to erase it, and the error went away when I typed a number.

The workaround was to create another local variable, and only set MyMaxRecords to that value if the value wasn't zero. 

Rank: #493

The MaxRecords is used to show the pagination number and to divide the step to paging

So, it cannot be NullIdentifier() or 0

Hope this help

Rank: #2927

Sure. My point is that the InitPagination code that is supplied by OutSystems does not properly guard against setting MaxRecords to 0, which means that we must do that whenever using the Pagination widget.