You need to sign in to do that
Don't have an account?
Vanitha Mani
refresh table in aura
Hi,
i have a table inside lightning component..aura iteration items comes from another lightning component..when i add the new record then the table should refresh and display the values..can anyone help me with that..
<div class="slds-m-around_xx-small">
<div class="slds-align--absolute-left">
<h1 class="slds-text-heading--small">Below are the 5 most recent work time entries</h1>
<br/>
</div>
</div>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title--caps">
<th scope="col"><div class="slds-truncate" title="Id">S.No</div></th>
<th scope="col"><div class="slds-truncate" title="Work Date">Work Date</div></th>
<th scope="col"><div class="slds-truncate" title="User">User</div></th>
<th scope="col"><div class="slds-truncate" title="Minutes">Minutes</div></th>
<th scope="col"><div class="slds-truncate" title="After Hours">After Hours</div></th>
<th scope="col"><div class="slds-truncate" title="Reason">Reason</div></th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.timeList}" var="time" indexVar="sNo" >
<c:Inlinechildtime single="{!time}" sNo="{!sNo + 1}"/>
</aura:iteration>
</tbody>
</table>
<br/>
<br/>
<center>
<div class="slds-m-around_xx-small">
<div class="slds-align--absolute-Center">
<h1 class="slds-text-heading--small">Do you need to add any additional work time?</h1>
<br/>
<br>
</br>
<br>
</br>
</div>
</div>
<button class="slds-button slds-button_success" type ="submit" onclick="{!c.actionhandler2}" >Yes</button>
<button class="slds-button slds-button_destructive" onclick="{!c.handleNext1}">No</button>
<br/>
<br/>
<br/>
<br/><br/>
<br/>
<br/><br/><br/><br/>
<aura:if isTrue="{!v.seeu}">
<div role="dialog" aura:id="Modalbox" class="slds-modal slds-fade-in-open ">
<div class="slds-modal__container">
<div class="slds-m-around--xx-large">
<lightning:card title="Work Time" iconName="custom:custom86" class="slds-p-around_medium">
<br/>
<lightning:recordEditForm aura:id="leadCreateForm2" objectApiName="SVC_Work_Time__c">
<lightning:messages />
<lightning:inputField fieldName="Ticket__c" value="{!v.recordId}"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Work_Date__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="User__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Minutes__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="After_Hours__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Reason__c"></lightning:inputField>
<br/><br/><br/>
<center>
<lightning:button type="submit" label="Save" variant="brand" onclick="{!c.handleOnSubmit}"/>
<lightning:button type="submit" label="Save and New" variant="brand" onclick="{!c.handleOnSubmit2}"/>
<lightning:button label="Close" onclick="{!c.closemodal}" variant="brand"/>
</center>
</lightning:recordEditForm>
</lightning:card>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open" aura:id="Modalbackdrop">
</div>
</aura:if>
how to refresh this table..
thanks
i have a table inside lightning component..aura iteration items comes from another lightning component..when i add the new record then the table should refresh and display the values..can anyone help me with that..
<div class="slds-m-around_xx-small">
<div class="slds-align--absolute-left">
<h1 class="slds-text-heading--small">Below are the 5 most recent work time entries</h1>
<br/>
</div>
</div>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title--caps">
<th scope="col"><div class="slds-truncate" title="Id">S.No</div></th>
<th scope="col"><div class="slds-truncate" title="Work Date">Work Date</div></th>
<th scope="col"><div class="slds-truncate" title="User">User</div></th>
<th scope="col"><div class="slds-truncate" title="Minutes">Minutes</div></th>
<th scope="col"><div class="slds-truncate" title="After Hours">After Hours</div></th>
<th scope="col"><div class="slds-truncate" title="Reason">Reason</div></th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.timeList}" var="time" indexVar="sNo" >
<c:Inlinechildtime single="{!time}" sNo="{!sNo + 1}"/>
</aura:iteration>
</tbody>
</table>
<br/>
<br/>
<center>
<div class="slds-m-around_xx-small">
<div class="slds-align--absolute-Center">
<h1 class="slds-text-heading--small">Do you need to add any additional work time?</h1>
<br/>
<br>
</br>
<br>
</br>
</div>
</div>
<button class="slds-button slds-button_success" type ="submit" onclick="{!c.actionhandler2}" >Yes</button>
<button class="slds-button slds-button_destructive" onclick="{!c.handleNext1}">No</button>
<br/>
<br/>
<br/>
<br/><br/>
<br/>
<br/><br/><br/><br/>
<aura:if isTrue="{!v.seeu}">
<div role="dialog" aura:id="Modalbox" class="slds-modal slds-fade-in-open ">
<div class="slds-modal__container">
<div class="slds-m-around--xx-large">
<lightning:card title="Work Time" iconName="custom:custom86" class="slds-p-around_medium">
<br/>
<lightning:recordEditForm aura:id="leadCreateForm2" objectApiName="SVC_Work_Time__c">
<lightning:messages />
<lightning:inputField fieldName="Ticket__c" value="{!v.recordId}"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Work_Date__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="User__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Minutes__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="After_Hours__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Reason__c"></lightning:inputField>
<br/><br/><br/>
<center>
<lightning:button type="submit" label="Save" variant="brand" onclick="{!c.handleOnSubmit}"/>
<lightning:button type="submit" label="Save and New" variant="brand" onclick="{!c.handleOnSubmit2}"/>
<lightning:button label="Close" onclick="{!c.closemodal}" variant="brand"/>
</center>
</lightning:recordEditForm>
</lightning:card>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open" aura:id="Modalbackdrop">
</div>
</aura:if>
how to refresh this table..
thanks
In your Apex Class Create a new method like following.
@AuraEnabled
Public static list<object> RetriveObject(){
list<object> lstObj = [SELECT Id,fields From object];
return lstObj ;
}
and call the above mehtod when you have gotten success message after inserting new record.
Afterdate, set this list of Record into timeList Attribute. your problam will be solved.
even then your issue not resolved then show me your complete code like parent HTMl,js and Child Html,Js And Apex Class.
I will try to fix your issue.
Thank you
>> https://salesforce.stackexchange.com/questions/174741/how-to-refresh-the-specific-lightning-component-not-the-lightning-page
In the above link there is a way to implement this and below is the answer stated:
If you are refreshing the component from the context of a parent, you don't need to use an event - you can expose a method to the parent and get it to call that.
If you are refreshing the component from within the child itself, you could either use an event or re-run your init routine.
So for a parent calling a public method:
<aura:method name="reInit" action="{!c.doInit}" description="Runs the init method again ">
The parent could get a reference to the child component and call childComponent.reInit()
For a parent totally refreshing the child, the parent could dynamically recreate the component:
//clear body of host component just in case
var hostComponent = component.find("enclosingComponent");
hostComponent.set("v.body", []);
$A.createComponent(
'c:YourChildComponent', {
"someParam":"someValue"
},
function(newComponent, status, errorMessage) {
//Add the new button to the body array
if (status === "SUCCESS") {
var body = hostComponent.get("v.body");
body.push(newComponent);
hostComponent.set("v.body", body);
} else if (status === "INCOMPLETE") {
console.log("No response from server or client is offline.");
} else if (status === "ERROR") {
console.log("Error: " + errorMessage);
}
}
);
From the child component If you are doing this from within the component, you can despatch an event to the parent if you want a total refresh, or run the reInit method yourself.
You can define a new COMPONENT event fire it to tell the parent that you want to be refreshed.
<aura:event type="COMPONENT" description="Event used to tell the parent to refresh" >
<aura:attribute name="componentName" type="string"/>
</aura:event>
In the child component:
<!--markup-->
<aura:registerEvent name="refreshChildComponent" type="c:RefreshChild"/>
//handler
var e = component.getEvent("refreshChildComponent");
e.setParams({ "componentName": "child1"});
e.fire();
In the parent component:
<aura:handler name="refreshChildComponent" event="c:RefreshChild" action="{!c.refreshChild}" />
In the parent helper, the same code as above could be called - in the parent calling a public method section
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
<div class="slds-m-around_xx-small">
<div class="slds-align--absolute-left">
<h1 class="slds-text-heading--small">Below are the 5 most recent work time entries</h1>
<br/>
</div>
</div>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title--caps">
<th scope="col"><div class="slds-truncate" title="Id">S.No</div></th>
<th scope="col"><div class="slds-truncate" title="Work Date">Work Date</div></th>
<th scope="col"><div class="slds-truncate" title="User">User</div></th>
<th scope="col"><div class="slds-truncate" title="Minutes">Minutes</div></th>
<th scope="col"><div class="slds-truncate" title="After Hours">After Hours</div></th>
<th scope="col"><div class="slds-truncate" title="Reason">Reason</div></th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.timeList}" var="time" indexVar="sNo" >
<c:Inlinechildtime single="{!time}" sNo="{!sNo + 1}"/>
</aura:iteration>
</tbody>
</table>
<br/>
<br/>
<center>
<div class="slds-m-around_xx-small">
<div class="slds-align--absolute-Center">
<h1 class="slds-text-heading--small">Do you need to add any additional work time?</h1>
<br/>
<br>
</br>
<br>
</br>
</div>
</div>
<button class="slds-button slds-button_success" type ="submit" onclick="{!c.actionhandler2}" >Yes</button>
<button class="slds-button slds-button_destructive" onclick="{!c.handleNext1}">No</button>
<br/>
<br/>
<br/>
<br/><br/>
<br/>
<br/><br/><br/><br/>
<aura:if isTrue="{!v.seeu}">
<div role="dialog" aura:id="Modalbox" class="slds-modal slds-fade-in-open ">
<div class="slds-modal__container">
<div class="slds-m-around--xx-large">
<lightning:card title="Work Time" iconName="custom:custom86" class="slds-p-around_medium">
<br/>
<lightning:recordEditForm aura:id="leadCreateForm2" objectApiName="SVC_Work_Time__c">
<lightning:messages />
<lightning:inputField fieldName="Ticket__c" value="{!v.recordId}"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Work_Date__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="User__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Minutes__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="After_Hours__c"></lightning:inputField>
<lightning:inputField aura:id="lookup" fieldName="Reason__c"></lightning:inputField>
<br/><br/><br/>
<center>
<lightning:button type="submit" label="Save" variant="brand" onclick="{!c.handleOnSubmit}"/>
<lightning:button type="submit" label="Save and New" variant="brand" onclick="{!c.handleOnSubmit2}"/>
<lightning:button label="Close" onclick="{!c.closemodal}" variant="brand"/>
</center>
</lightning:recordEditForm>
</lightning:card>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open" aura:id="Modalbackdrop">
</div>
</aura:if>
controller:
when next button is clicked from one page to this table page
var action = component.get("c.fetchtime");
var recordId = component.get("v.recordId");
action.setParams({
recordId : recordId
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
component.set("v.timeList", storeResponse);
}
});
$A.enqueueAction(action);
},
Apex class:
public static List<SVC_Work_Time__c> fetchtime(String recordId){
return [SELECT Id,Ticket__r.Id,Work_Date__c,User__r.Name,Minutes__c,After_Hours__c,Reason__c from SVC_Work_Time__c where Ticket__r.Id =:recordId order by Work_Date__c DESC limit 5];
}
child component:
<aura:attribute name="sNo" type="string" />
<aura:attribute name="single" type="sobject" default="{'sobjectType' : 'SVC_Work_Time__c',
'Work_Date__c' : '','User__c' :'','Minutes__c' :'',
'After_Hours__c': '','Reason__c' :'',
}"/>
<tr>
<td><div class="slds-truncate">{!v.sNo}</div></td>
<td><div class="slds-truncate">{!v.single.Work_Date__c}</div></td>
<td><div class="slds-truncate">{!v.single.User__r.Name}</div></td>
<td><div class="slds-truncate">{!v.single.Minutes__c}</div></td>
<td><div class="checkbox">{!v.single.After_Hours__c}</div></td>
<td><div class="slds-truncate">{!v.single.Reason__c}</div></td>
</tr>
</aura:component>
Hi vanitha,
You can also use e.force:refreshView through which without refreshing the page it will refresh the content i.e table records.
https://developer.salesforce.com/docs/component-library/bundle/force:refreshView/documentation
Thanks