I'm trying to Expand All/Hide All in lightning:accordion Lightning aura component.

        <aura:iteration items="{!v.pboW.listPb}" var="pbW">

            <lightning:accordionSection name="{'S' + !pbW.index}" label="{!pbW.pb.Name}">
                     -- complex content goes here--

Saw below example in Documentation and I tried to set activeSectionName assuming it might help. Expand multiple sections

My Js controller code for Expand/Collapse All:

switchExpandAll: function(component, event, helper) {
    var viewAll = (component.get('v.viewAll')==true);
    viewAll = (!viewAll);
    component.set("v.viewAll", viewAll);

    var expandedSections = [];

        var pboW = component.get("v.pboW");
        for(var idx = 0; idx < pboW.listPb.length; idx++){
    console.log('expandedSections '+expandedSections);

But it seems not refreshing accordingly. Really appreciate any thoughts, suggestions to achieve Expand All/Collapse All sections.



You can show or hide all sections using activeSectionName attribute. Also allowMultipleSectionsOpen should be set to true. Sample code:


<aura:attribute name="activeSections" type="List" default="[]" />
<aura:attribute name="activeSectionsMessage" type="String" default="" />

<lightning:button label="Show" onclick="{!c.ShowHideAll}" />

<p>{! v.activeSectionsMessage }</p>

<lightning:accordion allowMultipleSectionsOpen="true"
                     activeSectionName="{! v.activeSections }" >
    <lightning:accordionSection name="A" label="Accordion Title A">
        Accordion Body A
    <lightning:accordionSection name="B" label="Accordion Title B">
        Accordion Body B
    <lightning:accordionSection name="C" label="Accordion Title C">
        Accordion Body C


ShowHideAll: function (component, event) {
    let activeSections = component.get("v.activeSections");
    if (activeSections.length === 0) {
    } else {
| improve this answer | |
  • Thanks @salesforce-sas I could figure out the issue with my code. – Pasan Eeriyagama Sep 5 '19 at 1:35

Figured out the issue.

It seems when I used expression name="{'S' + !pbW.index}" in <lightning:accordionSection name="{'S' + !pbW.index}" label="{!pbW.pb.Name}"> it did not work because I had used incorrect expression mistakenly.

Fixed below,


<lightning:accordionSection name="{! 'S' + pbW.index}" label="{!pbW.pb.Name}">
| improve this answer | |
  • 1
    Merge fields are in the form of {! ... }. The correct version would be {!'S'+pbW.index}. – sfdcfox Sep 5 '19 at 5:53
  • @sfdcfox Oh too bad, Didn't notice that until now! Thank you very much! – Pasan Eeriyagama Sep 5 '19 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.