You need to sign in to do that
Don't have an account?
Nyshaa
Controller:
Helper:
Display multiple table in a single lightning table
I have created a lightning component
I am displaying my data in a Lightning data table format
Now, I want to create 3 tables to display these 3 records seperately.
i.e I want a table to show the details of Service Name A , And similary for Service Name B & C
At the end of all the three tables I want to show the Sum of Total Cost & Effort.
How can I create 3 data table in a single component to display 3 records seperately
Apex Controller:
public with sharing class ASDcompanyapex { @AuraEnabled public static List<Service_Line__c> getServiceLine(string recordId) { List<Service_Line__c> ServiceLineList =[Select Name, Status__c, Line_Type__c, Total_Effort_Taken__c,Total_Line_Cost__c from Service_Line__c where Service_Request__c =: recordId]; system.debug(ServiceLineList); return ServiceLineList; } }Component:
<aura:component controller="ASDcompanyapex" implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes" access="global"> <aura:attribute name="recordId" type="Id" /> <aura:attribute type="Service_Line__c" name="ServiceLineList"/> <aura:attribute name="mycolumns" type="List"/> <aura:attribute name="data" type="List"/> <aura:handler name="init" value="{!this}" action="{!c.servicelist}"/> <lightning:datatable data="{! v.data }" columns="{! v.mycolumns }" keyField="id" hideCheckboxColumn="true"/> </aura:component>
Controller:
({ servicelist : function(component, event, helper) { var rid = component.get("v.recordId"); helper.fetchServiceLineHelper(component, event, helper); } })
Helper:
({ fetchServiceLineHelper : function(component, event, helper) { debugger; var action = component.get("c.getServiceLine"); var rec = component.get("v.recordId"); action.setParams({ "recordId": rec }); action.setCallback(this, function(response){ debugger; var state = response.getState(); debugger; if (state === "SUCCESS") { component.set('v.mycolumns', [ {label: 'Service Line Name', fieldName: 'Name'}, {label: 'Status', fieldName: 'Status__c'}, {label: 'Line Type', fieldName: 'Line_Type__c'}, {label: 'Total Effort', fieldName: 'Total_Effort_Taken__c', type: 'number', cellAttributes: { alignment: 'left' }}, {label: 'Total Line Cost', fieldName: 'Total_Line_Cost__c', type: 'currency'}, ]); debugger; var res = response.getReturnValue(); component.set("v.data" , res); debugger; } }); $A.enqueueAction(action); } })
To create individual datatable for each record, you need to make map<Id, List<sObject>> and iterate over this map and pass list<sObject> to datatable, as data attribute accpets list. Something like this:
APEX: CMP: CONTROLLER: HELPER: Hope this helps!
@Nyshaa Did you get the answer? I am also having similar requirement, could you please share if you were able to figure out the solution?