Hola, Code-Ninja! 😁
Happy to see you again, sorry for the late response! It really surprises me how creative you can be with this kind of situations
Before starting, I'd say that I liked too much your idea of doing the calculation and then placing that result in the database. Something like:
{
Item1
Calculates total of Item1
Saves that total in the row of Item1
}
Loop
{
Item2
Calculates total of Item2
Saves that total in the row of Item2
}
Loop...
Until it finishes all items in list
1) You are working on a dynamic or non-dynamic page?
It is a dynamic page
2) Your repeater is placed on a dynamic or non-dynamic page?
It is a dynamic page
3) Your repeater is connected with your database trough a dataset?
Yes, it is
4) The name element inside your repeater is connected to your dataset (inside property-panel)
Yes, they are
5) Your image-element inside your repeater is connected to your dataset (inside property-panel).
Yes, it is
6) Your FREE-TEXT is connected to anything. --> of course without any functionality, yet.
That's right
Where is your code?
Okay, I'll show you my code for calculating the result I want (you'll know more about how I calculate this and the explanation of it in the next questions):
export function columnStrip3_viewportEnter(event) {
let total;
let filter = wixData.filter();
total = "Item1";
if (total){
filter = filter.eq("material","Item1");
}
wixData.aggregate("Inventario")
.filter(filter)
.sum("cantidad", "total")
.run()
.then ((result) => {
var income = result.items[0].total
$w('#total').text = income.toLocaleString()
})
}
(I know, I'm not the best at coding, but this is what I do and it works 😅)
• The database "Inventario" is where all movements are saved (items in, items out)
• This code gives me only the total of Item1 available (and shows it in $w('#total'). What I want is to save that result (in column "Stock", we'll see it later) and then, automatically, loop to Item2, Item3...
-What to calculate?
In a nutshell, the total of items in an inventory. For example, (there were +3 Items1, and -1 Item1, so the result I want to save is 2, that is the total of Item1 I have available)
-Where to get data from for calculation ?
Okay, I've got 2 databases. In the first one you can see the movements (items in, items out) of my materials, this is the database "Inventario":
(as you can see, here I save the movements)
Okay, then
The second database is the one where all my items are saved:
This is "Item1", "Item2", "Item3"... The are ordered from A to Z
This database is also the one that is connected to the repeater. So, I the empty column, named "Stock", I want to save there the total available, let's use the previous example, there were +3 Items1, and -1 Item1, so the result I want to save is 2, that number (number two) is the one that has to be saved in the column "Stock", when it finishes saving, so it goes for Item2, Item3...
1) When exactly starts your process? User clicks on a button? Where this button can be found --> inside repeater / outside-repeater?
I'd like the trigger to be a "viewportEnter", outside-repeater
2) Ok, we know you want to loop trough all of the repeater, items and doing some calculations?
Well, yeah, every item has its own calculation (the result of Item1, Item2...)
3) We also know, that some of your elements are connected with your dataset and some not.
That's right. What I'm thinking (using your point of view that I liked too much) is to connect the no connected elements ("free text") to the "Stock", that is the result that has to be shown
4) How does look your database?
It is already shown
5) How does look like your current working/not working code?
It is already shown
Thank you so much for your time and answer!