next and previous button

my next and previous buttons work in preview and not in live mode.

i checked permissions and dataset mode - all seems ok.
this is a page which displays and edits data so dataset needs to be ‘read and write’
can anyone look at the code below and suggest possible solutions please?

thank you

import {local} from “wix-storage”;
import wixLocation from ‘wix-location’;
const linkField1 = “link-Sales-Notes-jobLog”; // replace this value
const linkField2 = “link-Sales-Fitters-jobDescription”; // replace this value
const jobdesc = “link-Sales-Description-jobDescription”; // replace this value

$w.onReady(function () {
$w(“#dataset1”).onReady(() => {
const numberOfItems = $w(“#dataset1”).getTotalCount();

$w("#dataset1").getItems(0, numberOfItems) 
  .then( (result) => {  

            const dynamicPageURLs1 = result.items.map(item => item[linkField1]); 

            local.setItem('dynamicPageURLs1', dynamicPageURLs1); 
            
            const dynamicPageURLs2 = result.items.map(item => item[linkField2]); 

            local.setItem('dynamicPageURLs2', dynamicPageURLs2); 
            
              const dynamicPageURLs8 = result.items.map(item => item[jobdesc]); 

            local.setItem('dynamicPageURLs8', dynamicPageURLs8); 

$w(“#previous1”).disable();
$w(“#next1”).disable();
$w(“#joblog”).disable();
$w(“#fitters”).disable();
$w(“#desc”).disable();

if (local.getItem(‘dynamicPageURLs’)) {
const dynamicPageURLs = local.getItem(‘dynamicPageURLs’).split(‘,’);
const dynamicPageURLs1 = local.getItem(‘dynamicPageURLs1’).split(‘,’);
const dynamicPageURLs2 = local.getItem(‘dynamicPageURLs2’).split(‘,’);
const dynamicPageURLs8 = local.getItem(‘dynamicPageURLs8’).split(‘,’);
const currentPage = ‘/’ + wixLocation.prefix + ‘/’ + wixLocation.path.join(‘/’);
const currentPageIndex = dynamicPageURLs.indexOf(currentPage);

if (currentPageIndex > 0) { 
  $w("#previous1").link = dynamicPageURLs[currentPageIndex - 1]; 
  $w("#previous1").enable(); 
              $w("#joblog").link = dynamicPageURLs1[currentPageIndex - 0]; 
                    $w("#joblog").enable(); 
                     $w("#desc").link = dynamicPageURLs8[currentPageIndex - 0]; 
                     $w("#desc").enable(); 
                    $w("#fitters").link = dynamicPageURLs2[currentPageIndex - 0]; 
                    $w("#fitters").enable(); 
} 

if (currentPageIndex < dynamicPageURLs.length - 1) { 
  $w("#next1").link = dynamicPageURLs[currentPageIndex + 1]; 
  $w("#next1").enable(); 
   $w("#joblog").link = dynamicPageURLs1[currentPageIndex - 0]; 
                    $w("#joblog").enable(); 
                                  $w("#desc").link = dynamicPageURLs8[currentPageIndex - 0]; 
                    $w("#desc").enable(); 
                    $w("#fitters").link = dynamicPageURLs2[currentPageIndex - 0]; 
                    $w("#fitters").enable(); 
} 

}
$w(“#dynamicDataset”).onReady( () => {
//assign the hasDoc variable the value of the field that holds the document in the current item of the dataset.
const q = $w(“#dynamicDataset”).getCurrentItem().quoteDocument;
const q1 = $w(“#dynamicDataset”).getCurrentItem().suppliedDrawings;
const q2 = $w(“#dynamicDataset”).getCurrentItem().associatedDocument1;
const q3 = $w(“#dynamicDataset”).getCurrentItem().materialsList;
const q4 = $w(“#dynamicDataset”).getCurrentItem().workingsOut;
const q5 = $w(“#dynamicDataset”).getCurrentItem().associatedDocument2;
if (q) { //check if hasDoc is true
$w(“#quotedoc”).show(); //enable the button
}
else { //check if haDoc is false
$w(“#quotedoc”).hide(); //change the button label
}
if (q1) { //check if hasDoc is true
$w(“#drawings”).show(); //enable the button
}
else { //check if haDoc is false
$w(“#drawings”).hide(); //change the button label
}
if (q2) { //check if hasDoc is true
$w(“#risk1”).show(); //enable the button
}
else { //check if haDoc is false
$w(“#risk1”).hide(); //change the button label
}
if (q3) { //check if hasDoc is true
$w(“#materials”).show(); //enable the button
}
else { //check if haDoc is false
$w(“#materials”).hide(); //change the button label
}
if (q4) { //check if hasDoc is true
$w(“#working”).show(); //enable the button
}
else { //check if haDoc is false
$w(“#working”).hide(); //change the button label
}
if (q5) { //check if hasDoc is true
$w(“#method”).show(); //enable the button
}
else { //check if haDoc is false
$w(“#method”).hide(); //change the button label
}
}
);

  } ) 
  .catch( (err) => { 
    console.log(err.code, err.message); 
 } ); 

} );
} );

Hi,
If the code works in preview mode it’s probably an issue with permissions or live data vs sandbox.
Check out these articles:

https://support.wix.com/en/article/how-to-set-permissions-for-a-database-collection
Good luck!
Roi.

Ok - I snyc’d sandbox with live data and now the buttons dont work in sandbox either

but i have found that if i delete records everything starts working once i have about 200 records

is there a maximum number of records or size of database?
i currently have 268 records

Good day,
My previous/next button show up in editor as an image but it doesn’t work when I preview the site. How do I make it an active button?
Thank you

$w.onReady(()=>{
	$w('#myImageElementIDhere').onClick(()=>{
		//do something here.....
	});
});

Thanks. So I need to add the code for the buttons? Very new to this. How do I add the code? Thank you again

  1. Activate the DEV-MODE (developer-mode) in your Wix-Editor first.

  2. Navigate to your wished page.

  3. Put this code to the CODE-Section of the choosen page. (on the bottom)

  4. The shown codewill just make the IMAGE functionaly and give it a click-function.

  5. You will have to expand the code and add some futher code-commands.

The image should now act like a button, but do not know what to do, when image is clicked.

This you will have also to code…

You want to create a NEXT/PREVIOUS-NAVIGATION using your IMAGE-Buttons.

Take a look onto this one…
https://www.wix.com/velo/reference/wix-dataset/dataset/hasnext
https://www.wix.com/velo/reference/wix-dataset/dataset/hasprevious

https://www.wix.com/velo/reference/wix-dataset/dataset/nextpage
https://www.wix.com/velo/reference/wix-dataset/dataset/previouspage

Just to describe the futher function in few words…

If hasNext = TRUE navigate to next …else do what?
If hasPrevious = TRUE navigate to previous …else do what?

Using simple if-else-queris.

if( something TRUE here ) { do something here } else { do something else here}

in CODING-language …

let hasNext =$w("#myDataset").hasNext();// true
if (hasNext===true) {console.log("TRUE")} else {console.log(""FALSE)}

gave you the wrong link…
here the right one to change items…

Good luck…:wink:

https://www.wix.com/velo/forum/coding-with-velo/hide-pagination-buttons-on-first-last-page-of-repeater/p-1/dl-60bd6a700980330015e1d3f0-60bc90d7d2c3db0015670a75-1?postId=60bc6b049ebe9c0015d82e87&origin=notification&replyId=60bd6a700980330015e1d3f0&commentId=60bc90d7d2c3db0015670a75

Thank you so much. This helps me a lot. I will let you know if I struggle at any point.