Hey guys,
I have a Repeater functioning as a Shopping Cart in which the amount per item is displayed inside the repeater.
I want to show the total of all items by calculating the totals from the repeater and showing it in a text element outside the repeater.
Can anyone point me in the right direction ?
Thanks Shan!
Solved!
For anyone who gets stuck doing this: https://www.wix.com/code/home/forum/questions-answers/trying-to-sum-db-values-with-a-loop
I am stuck here, Can you help ?
$w.onReady(() => { let user = wixUsers.currentUser; let userId = user.id; wixData.query("Cart") .eq("userId",userId) .find() .then((results) => { $w("#dataset1").setFilter( wixData.filter() .eq("userId",userId) ); }); wixData.query("Cart") .eq("userId",userId) .find() .then( (results) => { let items = results.items; items.forEach((item) => { //did the forEach as you said sum = (item.gtotal); $w("#cgtotal").text = String(sum); //total should be displayed here }); })
I suggest using the forEachItem function to loop through all of the repeater's items and sum up the total. You can then show that total in an element outside the repeater.