2

I can't find a solution to resolve this problem. I have this table:

<table>
<aura:iteration items="{!v.fixedDocs}" var="docs" indexVar="index">
                <tr>
                    <td><aura:text aura:id="nomeDoc" value="{!docs.Label}"/></td>
                    <td><aura:text aura:id="tipo" value="{!docs.Document_Type__c}"/></td>
                    <td><aura:text aura:id="stato" value="{!docs.State__c}"/></td>
                    <td><aura:text aura:id="firmatari" value="{!docs.Firmatari__c}"/></td>
                    <td><lightning:input aura:id="file" type="file" label=" " name="file" multiple="false" accept=".pdf, .doc, .docx" onchange="{!c.save}"/></td>
                    <td>
                        <lightning:button class="deleteButtons" label="" iconName="utility:delete" iconPosition="left" onclick="{!c.deleteRow}"/>
                        <lightning:button class="saveButtons" variant="brand" label="" iconName="utility:download" iconPosition="left"/>
                    </td>
                </tr>
            </aura:iteration> 
</table>

In the last column I have two buttons, one to delete the row and the other to save the information. How can figure out which row is interested in the action? I tried to assign the index variable to the lable and to aura:id of the button so later I could know which row is interested but these attribute don't support expressions and so I can assign to them only a static string. How can I resolve that? Thanks in advance.

4

you may use tabindex to get index from Lighting:button

<lightning:button tabindex="{!index}" class="deleteButtons" label="del" iconName="utility:delete" iconPosition="left" onclick="{!c.deleteRow}"/>

In controller

  deleteRow:function (component, event, helper) {
         console.log("Check",event.getSource().get("v.tabindex"));
    }
1
  • 1
    thank you very much man. You save my *** for the second time! Vote my question, please. – DarkSkull Apr 11 '17 at 12:47
1

I agree aura:id does not take any expressions, however the other html attributes would take, So a simple way would be to use "label" to hold your ids.

<td>
    <lightning:button class="deleteButtons" label="{!doc.Id}" iconName="utility:delete" iconPosition="left" onclick="{!c.deleteRow}"/>
    <lightning:button class="saveButtons" variant="brand" label="" iconName="utility:download" iconPosition="left"/>
</td>

Notice that label = {!doc.Id}, we can get them through event.getSource()

Your click handler will be as follows

deleteRow : function(component, event, helper){
    var source = event.getSource(); // this would give that particular component
    var recordId = source.get("v.label"); // returns the id
    /* Make the server side action with this recordId as a parameter */
}

I dont think there is a force:deleteRecord yet something similar to force:createRecord event, hence you might have to call the @Aura-Enabled methods to do the delete.

4
  • No, I've already written that this doesn't work. I think that all attributes of lightning component can't contains dynamic content. – DarkSkull Apr 11 '17 at 9:54
  • Hmm .. labels are supposed to work AFAIK .. developer.salesforce.com/docs/atlas.en-us.lightning.meta/… – Last Viking Apr 11 '17 at 9:57
  • And if lighnting component attributes does not take expression. Then i guess we will have to go for slds-buttons (custom markup ) – Last Viking Apr 11 '17 at 10:00
  • Neither because with Locker Service you don't target element with document.getElementById() or other similar methods. – DarkSkull Apr 11 '17 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.