Limit dataset display by Code

On my homepage, I have a repeater that connected to a dataset, and on the dataset, i have 5 items, and i only want to display 3 of them at each time

But i use code to shuffle which item to display, so it cancel the 3 display limit set on the dataset settings.

How can i override this?

let items;
function shuffleArray() {
 let itemsLength = items.length, lastItem, randomIndex;
 while (itemsLength) {
      randomIndex = Math.floor(Math.random() * itemsLength--);
      lastItem = items[itemsLength];
      items[itemsLength] = items[randomIndex];
      items[randomIndex] = lastItem;
  }
 return items;
}
$w.onReady( () => {
  $w("#dataset1").onReady( () => {
    $w("#dataset1").getItems(0, 5)
    .then( (results) => {
      items = results.items;
    $w("#repeater4").data = shuffleArray(items);
  })
  })
})

Hi @vuerarealestate ,

In your case, you should get all items from dataset (so do not set limit in the dataset) to do the array shuffle function.

Then, trim/split the array with the first 3 items only.

Set repeater (that is not linked to the dataset directly in the Editor) data to the 3 items.

You are very close to the goal!

Certified Code

Hello, I already get all the items on the dataset, it does shuffle on the real page, but the problem is it shows all 5 items, not 3 items only

Everytime i refresh the page it shuffles, but i wanted to display 3 items only not 5, any suggestions?