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(() => {
        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?


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.