Sum up calculations in a repeating group to get a total outside the RG, using custom states.
Setup time: 5 mins. Here’s an example of a shopping cart: Demo and Editor.
Add a custom state in the RG for the current sub-total;
Add another custom state in the RG to track the previous value;
Add a custom state outside the RG to hold the grand total;
Set up a workflow when one (or either) of the inputs change:
– Set the value of the “subtotal” custom state = price * quantity (values in the input boxes)
– Set the value of the “grand total” custom state = Grand total’s value + Subtotal - Previous Value
– Set the “previous value” custom state = subtotal
Simple as that! Hope that’s clear - let me know if any questions.
That looks fantastic! Thank you so much! I’m snowed under with something else at the moment but I was excited to check this out and you’ve done it. I’m going to get back into my app soon hopefully and I’ll definitely be incorporating this methodology.
Thanks again. Revel in your greatness!
All the best
Excellent. Thank you! I’ve spent ages looking at it today and just had to do a minor tweek to the maths in one of the work flows to accommodate a difference in how my RG works.
I’m hugely grateful!!
Thank you again.
I got this to work based on your much appreciated help. Thank you again.
Now, however, in order to save screen space, I’ve made a slight change which has dumbfounded me and sent me back to square one.
Basically, I’ve set my RG to 1 Row and Full List so that if newly selected items are added to it the list grows. This seems to work very differently to your example which has all items in the list.
Is there a way to effectively do the same thing (ie maintain a Grand Total outside of the RG while items are added and quantities are changed?) for a fixed, one row, full RG? This seemingly subtle difference appears to have a massive impact on the workflows and I’ve stuck trying to get it to calculate. I’d appreciate any wisdom on this new twist.
Many many thanks in advance.
@lcsinteriors For subtotals and taxes, I’m using RepeatingGroup Tools to calculate taxes and subtotals. It’s not free, but gets the job done perfectly and quickly.
How would you get that data out of that repeating group and create an order with the total/subtotals? From what I can find, the only solution would be to add a + button to each RG row and then creating cartItems in the database. Then have a place order button that creates the order, adds all those newly created cartItems to the order data type.
Ideally, I’d like to be able to create a custom state that holds the cartItems prior to saving them to the database. A custom state (list of cart items) the cartitem needs to exist on the page before you can add it to the custom state. Is there a way to dynamically create the cartItem and add that to the custom state that can then be passed to the order?
Currently, I’m doing the former, but would really like to be able to do the latter.
Thanks a lot @robhblake!! That worked really well! However i bumped into another problem that i’m trying but can’t figure out how to fix.
How can the grand total show up when the page loads? I have this list of workers already saved and showing in the repeating group, but every time the page is loaded, i have to change at least one input from each line so the grand total shows the right value.
Is there a way to do it using the states?
It’s my first time using bubble so i much appreciate the help!!