Austin Troth
Posts: 0
Joined: Wed Feb 26, 2014 4:54 am

Pagination code to make next button hide when total is less than limit

I am working with pagination and I am trying to get the "next" button to show at the bottom of the page if the search results have more than 100 items. I have a service that counts the results of my query and i have tested the results of this with a mapping and it does put out the correct number. I have put this bit of java anywhere i can think of it working but it does not show the next button in the proper instances. I have tried to put it at the end of the success event. The count is mapped to the local storage string "total" and the button is hidden when the search is started. Any help would be great. thanks

Side note: I have followed the pagination tutorial on the next and previous button with similar code as below and they work just fine. Thanks

var Total = parseInt(localStorage.getItem('total'));
var Limit = parseInt(localStorage.getItem('limit'));
if (Total Limit) {
Apperyio('search2_pageChange_title').show();
}

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Pagination code to make next button hide when total is less than limit

Hello Austin,

Please use query parameter "skip" for that, instead of "limit": https://devcenter.appery.io/documenta...

Austin Troth
Posts: 0
Joined: Wed Feb 26, 2014 4:54 am

Pagination code to make next button hide when total is less than limit

I have tried just comparing it to a number and it doesn't work. If (total < 100) {

Austin Troth
Posts: 0
Joined: Wed Feb 26, 2014 4:54 am

Pagination code to make next button hide when total is less than limit

Also isn't the skip for the first page 0? How does comparing my total to skip help decide if there is more than one page? Type

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Pagination code to make next button hide when total is less than limit

Yes, for the first page that value is 0.

E.g. you have 250 total items, and you want to show only 10 items on the page.

1) For the first page:
skip = 0;
limit = 10;

2) Second page:
skip = 10;
limit = 10;

3) For the X page you have to use:
skip = 10 * (X - 1)

Austin Troth
Posts: 0
Joined: Wed Feb 26, 2014 4:54 am

Pagination code to make next button hide when total is less than limit

Yes..? I'm not sure you understand my question. I want to hide the next button when the first page has less results than the limit of the page. I.e. I have 1000 items in my database. I want to show 100 items at a time (limit=100). Skip is zero for the first page. If the query runs and results in 26 items, which is less than my 100 limit, the next button should hide because there is no second page to go to.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Pagination code to make next button hide when total is less than limit

Please look at this link how to show/hide any component with JS: https://docs.appery.io/reference#exam...

so, on the success event of the service check a response length, and if it is less than 100 - hide a nextButton:
preif(data&#46;length < 100){
Apperyio("nextButton")&#46;hide();
} else {
Apperyio("nextButton")&#46;show();
}/pre

Austin Troth
Posts: 0
Joined: Wed Feb 26, 2014 4:54 am

Pagination code to make next button hide when total is less than limit

This solution worked perfectly. Thank you

Return to “Issues”