Why does my hasNextPage() always return false?

I thought that hasNextPage() returns only false if it is the last page in the dataset. I receive on all 4 pages false :frowning:

I have a dynamicDataset with 4 entries in it (see image below).


On page with the Dynamic Page Dataset the mode is: Read & Write.
On this page I run the following code:

$w.onReady( function () {
$w(‘#dynamicDataset’).onReady(()=>{
let hasNextpage = $w(“#dynamicDataset”).hasNextPage();
console.log(hasNextpage);
});
//if user likes or dislikes, move to the next page of the dynamicDataset
$w(“#Like, #Dislike”).onClick(()=>{
$w(“#dynamicDataset”).getNextDynamicPage()
.then((next)=> {
if (next){
wixLocation.to(next);
}
});
});
});

Does anybody know why console.log(hasNextPage) is always false?

Hey there!
When you are on a Dynamic Page the Dataset you use has only one record so that is why you will get false. Then you should have used hasNext() which will check for next item, hasNextPage() will check for next page of a item using a Dynamic Dataset but this does not work. But you can not use this on Dynamic Page or on Datasets with only one record.

If you use console.log($w(“#dynamicDataset”).getTotalCount()); you will get 1 as the results so there is only one record. You can use the Next and Previous buttons though I think.

1 Like

Hey there!
I made a solution for you that works. Here is the solution:
https://wixshow.wixanswers.com/en/article/check-if-there-is-a-next-item-on-a-dynamic-page

1 Like

ok, sometimes its the simple things in life -.- I was thinking way more complex. but thank you Andreas, you are awesome

1 Like

@nojannourbakhsh thanks man, I am blushing. If you like it and it works please mark as top comment. It helps me.

@andreas-kviby

I have still a problem. the code below returns all the time: “Buttom is enabled” until it reaches the final page. On the final page I would like to enable the button, as I need to know if the user likes or dislikes also the final image. Nevertheless, my else statement is never executed. Thus, the buttons remain non-clickable :confused:

$w(“#Like, #Dislike”).onClick(()=>{
{some code}
//returns true if next page and nothing if no next page
if ($w(“#Like”).enabled=== true ){
console.log(“Buttom is enabled”);
} else {
$w(“#Like”).enable()
.then( () => {
console.log(“Element now enabled again”);
} );
}
});

@nojannourbakhsh Hey
You need to add one invisible button that has the action Next Dynamic Page setup, not the Like button then after checking the invisible button you will set the like button / dislike button to enabled as long as the invisible button is enabled and when invisible button is disabled there are no more records to move on to.