I have lightning buttonIcon in table for every record.When I click the buttonIcon on each row it has to change icon name from utility:add to utility:check.Even though if I select each row and try to change the icon in onclick event all rows button icons are getting changed.
<aura:iteration items={!v.mydata} var ="obj" indexvar="index">
<tr id={!index}>
<td>
<lightning:buttonIcon iconName="{!v.icon}" title="Default"
alternativeText="Default" onclick="{!c.add}" />
</td>
<td class="" data-label="Name">{!obj.Name}</td>
<td class="" data-label="Type">{!obj.Type}</td>
<td class="" data-label="Age">{!obj.Age}</td>
</tr>
</aura:iteration>
({
add: function(component, event, helper) {
component.set("v.icon", component.get("v.icon")=="utility:add"?
"utility:check":"utility:add");
}
})
Best Answer
You have stored icon in single attribute (v.icon) which changes for each and every iteration of your object.
So you can store icon name in your v.mydata variable
Now onclick