You need to sign in to do that
Don't have an account?
Henry Moser
Updating sum in parent component from child components
I have a parent component that iterates through a list of objects that are displayed in child components. Each child component has an input for an integer (default 0), and the parent component has an attribute that needs to be displayed as the sum of all child components' inputs.
What's the method of dynamically displaying the sum from the parent on change to any of the child components' input?
What's the method of dynamically displaying the sum from the parent on change to any of the child components' input?
https://developer.salesforce.com/blogs/developer-relations/2015/03/lightning-component-framework-custom-events.html
http://bobbuzzard.blogspot.com/2015/05/lightning-component-events.html
https://www.sfdcstop.com/2018/04/salesforce-lightning-events-part-2.html
https://www.sfdcstop.com/2018/04/salesforce-lightning-events-tutorial.html
1) Create an event of type "COMPONENT"
2) In the child component, create a change handler on the integer attribute.
3) In your controller, in the handleCountChange, get the event you created in step 1, set the count attribute as a parameter and fire the event.
4) In the parent component, declare a handler for the event created in step 1. Also keep an attribute to roll up the count. Increment this count when you handle the event.
Hope this helps.