I’m trying to sort my dataset according to the option chosen in the dropdown menu, but the website doesn’t seem to pick up on my sort until I perform another dropdown_change - to which it’ll respond to the previous dropdown change.
export function dropdown1_change(event, $w) {
if ($w(“#dropdown1”).selectedIndex === 0) {
filterChange(“popularity”);
refresh();
} else if ($w("#dropdown1").selectedIndex === 1) {
filterChange("releaseFrequency");
refresh();
function filterChange(sortBy){
$w(“#metricDataset”).setSort( wixData.sort().descending(sortBy));
//Calculates ranking of libraries.
$w(“#metricDataset”).getItems(0,4)
.then( (result) => {
let items = result.items;
let totalCount = result.totalCount;
for(var i = 0; i < totalCount; i++){
$w(“#rank” + (i+1) + “Text”).text = items[i].title;
}
});
}
function refresh(){
$w(“#metricDataset”).refresh();
}
So if I were to visit the website, use the best by: dropdown and select release frequency, the ranking would be the ranking for popularity, but if I then select popularity in the dropdown, I’ll get the ranking for release frequency.
https://martelsg.wixsite.com/libravis/mocking
Am I doing something wrong?