I have a database like this
I want to display the "price" total.
my code is
wixData.aggregate("gckj2gyh")
.sum("price")
.run()
.then( (amount) => {
const sumTotal =0;
let items = amount.items;
items.forEach(item =>{
{sumTotal+item.value;
}
});
$w('#text10').text = ""+ sumTotal;
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
But always the total is 0.
please tell me how to fix this.
thank you for your readings
@rlussian-dima, Thanks I am also looking for this script.
What exactly do you want to count?
Here you are talking about ROWs which you want to count in a database.
That was my answer....
$w.onReady(async function() { wixData.query("gckj2gyh") .eq("title", true) .count() .then((num) => { $w('#text9').text= String(num); }) .catch( (error) => { let errorMsg = error.message; let code = error.code; }); });
Or something like this one...?
var myDataset = '#dataset1' var myTable = '#table1' $w(myDataset).onReady(function(){ var total = 0; for (var i = 0; i < $w(myTable).rows.length; i++) { console.log($w(myTable).rows[i]["total"]); total = Number(total) + Number($w(myTable).rows[i]["total"]); console.log ("Total:" + total); } $w('#text12').text = String("$" + total); });