Random Order for Repeater Items on Page Ready


The following code assumes your repeater is hidden on load and that you are filtering your dataset when the page loads.  Adjust the code as needed (including the element ID names).

You can see this code being used on this live page:  https://www.totallycodable.com/featured-designers


Good to Know #1

The Code

import wixData from 'wix-data';

$w.onReady(async function () {
    $w("#dataset1").onReady(async () => {

                .eq("designer", "designer")  //Our example sets a filter before running the randomization code
            .then((results) => {
 let repeaterItems = $w('#repeater1').data;
                $w('#repeater1').data = shuffle(repeaterItems);
            .catch((err) => {
 let errorMsg = err;


function shuffle(items) {
 var currentIndex = items.length,
        temporaryValue, randomIndex;
 while (0 !== currentIndex) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
        temporaryValue = items[currentIndex];
        items[currentIndex] = items[randomIndex];
        items[randomIndex] = temporaryValue;
 return items;



by Code Queen

Stuck on a project? Hire Code Queen, LLC!

Schedule a phone call or video call directly online. In a different time zone? No problem! Code Queen currently has clients around the world.

Online Booking: Discovery Session

Contact Form: Send project details

176 views0 comments