How to use setSort function to sort a dataset within a repeater?

I am trying to set up a way for my site visitors to use a dropdown with SORT options so they may ‘sort by’ the data within the repeater on the page.

I’ve created a dropdown element which i’ve connected to an event handler (onClick). Upon the user clicking one of the fields to sort by (A-Z, Capacity, Sq. Ft) the data within the repeater is manipulated on the page. But it is NOT correct.

Further explanation: the dataset in this repeater is for a list of venues. Upon clicking ‘sort by’ : ‘capacity’ the dataset changes order but it is not actually changing correctly because the capacity is not being listed in ascending order. or descending for that matter. It seems to be random. I see no pattern in the order so it makes it harder to debug. would appreciate some advice on this. thanks!

also, here’s a pic for reference

Hi Josh,

When passing values to ascending( ) , and descending( ) you should pass the field ID that you want the results to be sorted with.

For example, if you want to sort the students by their names, A-Z:

const sort = wixData.sort().ascending('name');

By their names Z-A

const sort = wixData.sort().descending('name');

If you want to sort the results by another data, replace the “name” ID with the field ID you want the items to be sorted with.

Hope this helps~!
Ahmad

That was the problem! Thank you, Ahmad!

@joshjnunez09 You’re welcome :blush: