Community X.

Connect with other creators, share ideas, give feedback and get the latest product updates.

Sep 23

Dynamically sort items in repeater

Is it possible to sort the items displayed using a repeater based on user input? I have a dataset containing paintings, and I would like to let the user sort these by title, year or subject by clicking buttons.


I tried using something along the lines of:


$w("#sortByTitleButton").onClick(() => {
        $w("#worksDataset").setSort(
            wixData.sort()
            .ascending("Title")
        );
        console.log("Sorting by Title");
    });

And, this does alter the sort order of the repeater items. But, the resulting order is incorrect. It's probably not random order. But, I can't make heads or tails of it. Any suggestions?

1
Sep 24

Hi,


Hope this helps someone else. The code above works if you lower-case the field name in the call to ascending(). Field names in collections in Editor X are typically init-capped. But, apparently, they're lc'd in Datasets.


Cheers,


Greg

Editor X

Design your boldest creations.