Code to Use Dropdown to Sort

Ok, you need a function that is going to receive the values you are going to get from the dropdown menu items, upon selection.

Let’s call this function sortData , and this function is going to receive a parameter with the sorting value, we are going to call it sorting . This function does not return anything, it just sets a variable that holds the sorting object and then sorts the dynamic dataset.

Then we need a $w(“#dropdown”) with the values that you used to sort, redAvg , yellowAvg , greenAvg and blueAvg .

And you can get it’s value when you change it, using the onChange() method and getting the dropdown value with it’s property value .

const sortData = (sorting) => {
  const sortObj = wixData.sort().descending(sorting)
  $w('#dynamicDataset').setSort(sortObj)
}

$w.onReady(() => {
  $w('#dropdown').onChange((e) => sortData($w('#dropdown').value))
})