Hello, newbie to wix code and need help. I had loaded a table to maintain standings for a league I’m managing.
Using this instructions from this url:
Velo Tutorial: Calculating and Displaying Collection Data | Help Center | Wix.com I was able to summary the data per player.
I need help to sort by Category and Total Points after I have loaded the table, but I haven’t found a way. Please help. Here is the code I’m using:
$w(“#tblstandings”).columns = [
{
“id”: “col1”,
“dataPath”: “person_name”,
“label”: “Player”,
“type”: “string”
},
{
“id”: “col2”,
“dataPath”: “total_points”,
“label”: “Total Points”,
“visible”: true,
“type”: “number”
}
];
wixData.query(“WeeklyScores”)
.ne(“points_earned”,0)
.ascending(“category_name”,“person_name”)
.limit(1000) // include a limit if you have more than 50 items
.find()
.then( (result) => {
const persons = result.items.map(x => x.person_name)
.filter((obj, index, self) => index === self.indexOf(obj));
const playersummary = persons.map(x => {
return {
person_name: x,
total_points: result.items.filter(obj => obj.person_name === x)
.map(z => z.points_earned)
.reduce((sum, current) => sum + current)
};
});
$w("#tblstandings").rows = playersummary;
});
Here is the end result that I’m looking for. Right now the data is sorted by player name in alphabetical order, but I needed by total points within the category.