Question:
Hello! I am looking to add a randomize button to my gallery, which is connected to a CMS collection. There are over 300 images so I would like the user to be able to randomize the order. Currently, I have the following code which handles a Sort Dropdown by Title. How could I add to this to implement a Random option?
import wixData from 'wix-data';
$w.onReady(function(){
$w('#sortDropdown').onChange((event) => {
const sort = $w("#sortDropdown").value;
switch (sort) {
case "Title: A-Z":
$w("#paintingsDataset").onReady(()=>{
$w("#paintingsDataset").setSort(
wixData.sort().ascending("title")
)
})
break;
case "Title: Z-A":
$w("#paintingsDataset").onReady(()=>{
$w("#paintingsDataset").setSort(
wixData.sort().descending("title")
)
})
break;
default:
$w("#paintingsDataset").onReady(()=>{
$w("#paintingsDataset").setSort(
wixData.sort()
)
})
break;
}
})
});
Product:
Wix Studio Editor.
What are you trying to achieve:
I’m trying to add a Randomize button for my gallery so users can randomize the order of the images and associated titles, descriptions, etc.