function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Henry MoserHenry 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?
Raj VakatiRaj Vakati
You can able to do it by using the events ..The effective mechanism by which two components can work is by using Events .Lightning framework works on Event driven paradigm .

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
Ravi Dutt SharmaRavi Dutt Sharma
Make use of component events.

1) Create an event of type "COMPONENT"

2) In the child component, create a change handler on the integer attribute.
<aura:handler name="change" value="{!v.count}" action="{!c.handleCountChange}"/>

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.