Activity Forums Salesforce Questions and Answers How to apply <lightning:accordion>  to make account clickable to fetch contacts in Lightning Component in Salesforce?

  • How to apply <lightning:accordion>  to make account clickable to fetch contacts in Lightning Component in Salesforce?

  • Deepak

    Member
    February 7, 2020 at 1:38 pm

    How to apply <lightning:accordion>  to make account clickable to fetch contacts in Lightning Component in Salesforce?

  • Rabn

    Member
    February 8, 2020 at 4:01 am

    Apex Class:

    public class AcctController {
        @AuraEnabled
        public static List<Account> getAccnt(){
            List<Account> categeroy = [Select  Name,Industry,Phone from Account];
            return categeroy;
        } 
        }

    Lightning Component:

    <aura:component controller="AcctController ">
        <aura:attribute name="acctList" type="Account[]" />
        <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
        
        <lightning:accordion aura:id="accordion">
            <aura:iteration items="{!v.acctList}" var="acct">
                <lightning:accordionSection name="A" label="{!acct.Name}" >
                    <aura:set attribute="body">
                        
                        <table class="slds-table slds-table--bordered slds-table--cell-buffer slds-table--striped slds-max-medium-table--stacked-horizontal"
                               role="grid">
                            <thead>
                                <tr>
                                    <th class="slds-is-sortable slds-cell-wrap" scope="col">
                                        Name
                                    </th>
                                    <th class="slds-is-sortable slds-cell-wrap" scope="col">
                                        Phone
                                    </th>
                                    <th class="slds-is-sortable slds-cell-wrap" scope="col">
                                        Industry
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <aura:iteration items="{!acct.Account}" var="accnt">
                                    <tr class="slds-hint-parent">
                                        <td role="gridcell" class="slds-cell-wrap">
                                            <div class="">{!accnt.Name}</div>
                                        </td>
                                        <td role="gridcell" class="slds-cell-wrap">
                                            <div class="" data-label="Role">{!accnt.Phone}</div>
                                        </td>
                                        <td role="gridcell" class="slds-cell-wrap">
                                            <div class="" data-label="Role">{!accnt.Industry}</div>
                                        </td>
                                        
                                    </tr>
                                    
                                </aura:iteration>
                            </tbody>
                        </table>
                    </aura:set>
                </lightning:accordionSection>
            </aura:iteration>
            
        </lightning:accordion>
        
        
    </aura:component>

    Controller:

    ({
        doInit : function(component, event, helper) {
            var action = component.get("c.getAccnt");
            action.setCallback(this, function(a) {
                component.set("v.acctList", a.getReturnValue());
            });
            $A.enqueueAction(action);
        }
    })

     

Viewing 1 - 2 of 2 posts

Log in to reply.

Original Post
0 of 0 posts June 2018
Now