How to filter, sort and display options on a dropdown?

Hi !
I have a database of 90 000 vehicles and three dropdowns on my page.
Here is my database :

Each of my repeaters are connected to the foolowing : Make (“make”), Model (“model”), Year (“year”)

Problem : I would like to build a function that would filter and set the options of each dropdown to be unique and sorted by alphabetical or numerical order.

I would be extremely glad if anyone would help :slight_smile:

thank you !

You could use the distinct function to arrive at a list of unique values for the three fields, something like this (guessing actual collection name) for the make dropdown:

 wixData.query("CarModelsList")
   .ascending("make")
   .distinct("make")
 .then( (results) => {
      $w("#make").options = buildOptions(results.items);
  })
  
function buildOptions(uniqueList) {
 return uniqueList.map(uniqval => {
 return {label:uniqval, value:uniqval};
        });
}