I’ve seen serval older posts with the opposite of this problem (always false), but I can’t figure it out.
I have a dataset with 4 records and the repeater is set to limit to 2 records per page.
On data ready I call getTotalPageCount()and it outputs 2 pages, as expected. I can also call hasNextPage() and it returns true, again as expected.
This is where things turn weird:
I have a transparent strip below the fold of my page and set the onViewortEnter to call loadMore() which works as expected (the first time). THEN I run a check to see if there are more pages to follow (hasNextPage()), if no, collapse the strip so it will quit calling. hasNextPage() always returns true! I started logging the total number of pages and the current page index with every call. The total number of pages stays at 2 (which is correct), but the page index keeps incrementing every time the loadMore() runs.
I’m sure this is a timing/callback issue, but I’ve tried everything. What am I missing/not understanding?
export function stripNextPage_viewportEnter(event) {
console.log($w("#dbProperties").getTotalPageCount()); // 2
console.log($w("#dbProperties").getCurrentPageIndex()); // Increments on each call
$w("#dbProperties").onReady(() => {
$w("#dbProperties").loadMore()
.then(() => {
console.log("Done loading more data");
$w.onReady(() => {
$w("#dbProperties").onReady(() => {
let hasNextPage = $w("#dbProperties").hasNextPage();
console.log(hasNextPage); // always returns true
//If no more pages exist collapse strip
if (!hasNextPage) {
$w("#stripNextPage").collapse();
}
});
});
});
});
}
Can confirm this issue still exists. I have the same use case as well.
I've tried adding a three-second timeout, but to no avail. hasNextPage() seem to always return true.
Upon further inspection, it seems that the loadMore() will work no matter what (probably due to the fact that hasNextPage() always returns true).
Here's an example of the logs. My dataset loads two items at a time. There's 12 items in total, so there should be six pages.
I have a recursive function that keeps loading as long as hasNextPage() is true. The getTotalPageCount() seems to work fine here.
pageIdx 1 // totalPages 6 hasNextPage true totalsize 12 pageIdx 2 // totalPages 6 hasNextPage true totalsize 12 pageIdx 3 // totalPages 6 hasNextPage true totalsize 12
However, once it reaches page six, where hasNextPage() should return false and the recursion stops, it keeps going.
Note that loadMore() continues to "work" without throwing an error, and the getCurrentPageIndex() is incremented beyond the page count returned by getTotalPageCount().
pageIdx 6 // totalPages 6 hasNextPage true totalsize 12 pageIdx 7 // totalPages 6 hasNextPage true totalsize 12 pageIdx 8 // totalPages 6 hasNextPage true totalsize 12 pageIdx 9 // totalPages 6 hasNextPage true totalsize 12
Here are the last few occurrences. hasNextPage still comes back at true each time. Also notice how getCurrentPageIndex increments well past the actual 5 pages.
5 5 Done loading more data {...} totalPage: 5 pageSize: 6 count: 25 hasNextPage: true 5 6 Done loading more data {...} totalPage: 5 pageSize: 6 count: 25 hasNextPage: true 5 7 Done loading more data {...} totalPage: 5 pageSize: 6 count: 25 hasNextPage: true
Yes i had the issue with last time too
The reason for that it
It's not a hasNextDynamicPage()
Note this function is not exist
and this is what you are looking for
For now just use
.getNextDynamicPage()
It will return the URL or an empty string "" if there is no URL
$w('#dynamicDataset').getNextDynamicPage() .then(url => { if(url) { // has Next dynamic page } else { // current page is the last dynamic page } })
For example if you have a category dynamic page
let say we have 10 product and limit for the category dynamic dataset is set to 5 (means show 5 product per dynamic page)
then if the user is on the first page
the repeater will show from 1-5 products and
hasNextPage will return true
On the Secod page hasNextPage should be false
and the repeater will show 5-10