You need to sign in to do that
Don't have an account?

Add row or delete row functionality using lightning component salesforce
How to create multiple records of an object using lightning component.Please give an example or sample code
You need to sign in to do that
Don't have an account?
Below is the sample code.
ContactList.cmp
ContactListController.js
ContactListItem.cmp
ContactListItemController.js
deleteContactEvt.evt (Component Level Event)
ApexController
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
I am facing issue in save and delete.
contactApp:
<aura:application >
<ltng:require styles="{!$Resource.SLDS100 +
'/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
<div class="slds">
<c:contactList />
</div>
</aura:application>
contactList.cmp:
<aura:component access="public" controller="ContactController">
<aura:attribute name="contacts" type="Contact[]" access="private"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
<aura:handler name="deleteContact" event="c:deleteContactEvt" action="{!c.removeContact}" />
<table class="borderCls">
<tr>
<th class="borderCls">Name</th>
<th class="borderCls">Phone</th>
</tr>
<aura:iteration items="{!v.contacts}" var="contact">
<c:ContactListItem contactRec="{!contact}"/>
</aura:iteration>
</table>
<button onclick="{!c.addContact}">Add Contact</button>
<button onclick="{!c.saveContacts}">Save Contact</button>
</aura:component>
contactListController.js:
({
doInit : function(component, event, helper) {
var action = component.get("c.getContacts");
action.setCallback(this, function(data) {
console.log(data.getReturnValue());
component.set("v.contacts", data.getReturnValue());
});
$A.enqueueAction(action);
}
,
addContact : function(component, event, helper){
var contacts = component.get("v.contacts");
var len = contacts.length;
contacts.push({
'Name':'Test Contact - '+len,
'Phone':'123'+len
});
component.set("v.contacts",contacts);
}
,
removeContact : function(component, event, helper){
var selCont = event.getParam("selectedContact");
var contacts = component.get("v.contacts")
var index = contacts.indexOf(selCont);
if (index > -1) {
contacts.splice(index, 1);
}
component.set("v.contacts",contacts);
},
saveContacts: function(component, event, helper) {
var selectedAccount = component.find("contacts");
var action = component.get("c.saveContacts");
action.setParams({
"contactList" : selectedAccount
});
action.setCallback(this,function(a){
component.set("v.contacts",a.getReturnValue());
});
$A.enqueueAction(action);
}
})
contactListItem.cmp:
<aura:component >
<aura:attribute name="contactRec" type="Contact" access="public"/>
<aura:registerEvent name="deleteContact" type="c:deleteContactEvt"/>
<tr >
<td> <div class="slds-form-element__control">
<ui:inputText aura:id="account Name" label="Account Name"
class="slds-input"
labelClass="slds-form-element__label"
value="{!v.contactRec.lastName}"
/>
</div> </td>
<td> <ui:button label="Delete" press="{!c.deleteContact}"/></td>
</tr>
</aura:component>
Please suggest code changes for save and delete functionalities.
Where is the VF page for displaying this ? or how to access this after taking all components and controllers?
Did you make it work ? if yes, can paste the code here pls.
thanks
SFDC dev