You need to sign in to do that
Don't have an account?
Aakanksha Singh
Rerender the list on submitting a new record in lightning component
Hi all,
How can i rerender a list on adding a record through popup which is a component itself?
Thanks in advance.
How can i rerender a list on adding a record through popup which is a component itself?
Thanks in advance.
i review your code and its so simple try this code -:
in your List component add this line after aura handler -:
and update your List componentController.js with blow code ( blod text)
HidePopUp:function(cmp,event){
var cmpTarget = cmp.find('Modalbox');
var cmpBack = cmp.find('MB-Back');
$A.util.removeClass(cmpBack,'slds-backdrop--open');
$A.util.removeClass(cmpTarget, 'slds-fade-in-open');
component.updateAcc(); // call <aura:method> for reload the account list on page
},
now when you add new account from pop up the list of account in list component will be Rerender
Thanks
if it work let me inform and mark it solve :)
All Answers
can you share your component and both controller code ?
I've created a list view of sobject Account in a component, in which there is a button which opens a pop-up which is a component containing form, in which there is a submit button, on click a new record is created and popup is closed at once, now i have to rerender the list also, in which the new record inserted should be displayed. For fetching and inserting the record i've followed the same method as in expense tracker, as in trailhead module/ lightning component developer's guide.
Thanks
hi Aakanksha Singh
jscontrolleryou can achive this by <aura:method> when you add new record by popup modal after add record call <aura:method> by js controller this method call doInit (or other js controller function) i write a sample example for you, as your requirement.
component (with bootstrap)
apex class (acclistController)
after you add new account the list is Rerender by <aura:method> call. focuse on bold text
Thanks
If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer. :-)
Actually popup is another compnent i.e <c:popup/> and insertion is done in that component and the account list itself acomponent in which pop up is present.
Thanks for helping me
<aura:component controller="AccListController">
<aura:attribute name="accounts" type="Account[]"/>
<aura:handler name="AccountEvent" action="{!c.HidePopUp}" event="c:Event"/>
<aura:handler name="init" value="{!this}" action="{!c.getAccount}" />
<ui:button class=" slds-button slds-button--neutral slds-float--right" press="{!c.ShowPopUp}">New Vehicle</ui:button>
<table class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
<thead>
<tr class="slds-text-heading--label ">
<th class="" scope="col">Account Name</th>
<th class="slds-is-sortable" scope="col">Account Number</th>
<th class="slds-is-sortable" scope="col">Account Source</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="account"><!--Dynamic Listing of Vehicles-->
<tr class="slds-hint-parent">
<td class="" data-label="Account Name" >
<a href="{! '#/sObject/' + account.Id + '/view'}">{!account.Name}</a>
</td>
<td data-label="Account Number" style="padding-left:0;"><ui:outputNumber value="{!account.accountNumber}" /></td>
<td data-label="Account Source" style="padding-left:0;">{!account.account Source}</td>
</tr>
</aura:iteration>
</tbody>
</table>
<div role="dialog" tabindex="-1" aura:id="Modalbox" aria-labelledby="header43" class="slds-modal ">
<c:PopUp />
</div>
<div class="slds-backdrop" aura:id="MB-Back"></div>
</aura:component>
Controller-
({
getAccount:function(component, event, helper) {
var action=component.get("c.getAccList");//get data from controller
action.setCallback(this, function(a) {
component.set("v.accounts", a.getReturnValue());//set data in the page variable
});
$A.enqueueAction(action);
},
ShowPopUp:function(cmp,event){
var cmpTarget = cmp.find('Modalbox');
var cmpBack = cmp.find('MB-Back');
$A.util.addClass(cmpTarget, 'slds-fade-in-open');
$A.util.addClass(cmpBack, 'slds-backdrop--open');
},
HidePopUp:function(cmp,event){
var cmpTarget = cmp.find('Modalbox');
var cmpBack = cmp.find('MB-Back');
$A.util.removeClass(cmpBack,'slds-backdrop--open');
$A.util.removeClass(cmpTarget, 'slds-fade-in-open');
},
})
PopUp component-
<aura:component implements="force:appHostable" controller="AccListController">
<ltng:require styles="{!$Resource.SLDS +
'/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
<aura:registerEvent name="AccountEvent" type="c:Event"/>
<aura:attribute name="account" type="Account"/>
<aura:attribute name="newAccount" type="Account"
default="{ 'sobjectType': 'Account',
'Name': '',
'AccountNumber': '',
'AccountSource': ''
}"/>
<div class ="wk_static">
<div class="slds-modal__container ">
<div class="slds-modal__header">
<div class="slds-grid">
<div class="slds-col slds-has-flexi-truncate">
<div class="slds-media slds-media--center slds-no-space slds-grow">
<div class="slds-media__body">
<p class="slds-text-heading--label slds-truncate">Account</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-middle" title="New Account">New Account</h1>
</div>
</div>
</div>
</div>
</div>
<div class="modal-body scrollable slds-modal__content slds-p-around--medium">
<div class= "slds-form--stacked">
<div class="slds-form-element">
<div class="slds-form-element slds-is-required">
<div class="slds-form-element__control">
<ui:inputText aura:id="Name" label="Account Name" class="slds-input" labelClass="slds-form-element__label" value="{!v.newAccount.Name}" required="true"/>
</div>
</div>
</div>
<div class="slds-form-element">
<div class="slds-form-element__control">
<ui:inputnumber aura:id="AccNum" label="Account Number" class="slds-input" labelClass="slds-form-element__label" value="{!v.newAccount.accountNumber}" required="true"/>
</div>
</div>
<div class="slds-form-element">
<div class="slds-form-element__control">
<ui:inputText aura:id="Accsource" label="Account Source" class="slds-input" labelClass="slds-form-element__label" value="{!v.newAccount.accountSource}" required="true"/>
</div>
</div>
<div class="slds-modal__footer">
<div class="slds-form-element">
<div class="slds-form-element__control">
<ui:button class="slds-button slds-button--neutral slds-not-selected" press="{!c.createAccount}">Submit</ui:button>
<ui:button aura:id="button1" class="slds-button slds-buttonneutral slds-not-selected" press="{!c.HideComponent}">Cancel</ui:button>
</div>
</div>
</div>
</div>
</div>
</aura:component>
Controller-
({
createAccount: function(component, event, helper) {
var nameField = component.find("Name");
var nm = nameField.get("v.value");
if(nm==''){
nameField.set("v.errors", [{message:"Account Name is a required Field."}]);
}else{
nameField.set("v.errors", null);
var newAccount = component.get("v.newAccount");
helper.createAccount(component, newAccount);
var compEvent = component.getEvent("AccountEvent");
compEvent.fire();
}
},
HideComponent : function(component,event,helper){
var compEvent = component.getEvent("AccountEvent");
compEvent.fire();
}
})
Helper-
({
createAccount: function(component, account) {
this.upsertAccount(component, account, function(a) {
var accounts = component.get("v.account");
accounts.push(a.getReturnValue());
component.set("v.account", accounts);
});
},
upsertAccount : function(component, account, callback) {
var action = component.get("c.saveAccount");
action.setParams({
"account": account
});
if (callback) {
action.setCallback(this, callback);
}
$A.enqueueAction(action);
},
})
Apex Controller is same as yours.
Thanx
i review your code and its so simple try this code -:
in your List component add this line after aura handler -:
and update your List componentController.js with blow code ( blod text)
HidePopUp:function(cmp,event){
var cmpTarget = cmp.find('Modalbox');
var cmpBack = cmp.find('MB-Back');
$A.util.removeClass(cmpBack,'slds-backdrop--open');
$A.util.removeClass(cmpTarget, 'slds-fade-in-open');
component.updateAcc(); // call <aura:method> for reload the account list on page
},
now when you add new account from pop up the list of account in list component will be Rerender
Thanks
if it work let me inform and mark it solve :)