function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anupama@28Anupama@28 

Lighting component else part is displaying before if.

Hi,

I have a lightning compnent exactly same as given in below link... 
http://sfdcmonkey.com/2018/10/22/data-table-pagination-checkbox-lightning/.

<aura:if isTrue="{!v.bNoRecordsFound}">
       <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_info" role="alert">
            <span class="slds-assistive-text">Error</span>
            <h2> ERROR MESSAGE </h2>
        </div>
        <aura:set attribute="else">
         --------------
             <table>
                   <!---- TABLE WITH DATA --->
             </table>
         -----------------
            </aura:set>    
     </aura:if>

Here, when the lightning component is loaded, even if there are no records to display in table of else section... still a blank table is displayed for a while and goes off... and later error message from if section is shown.
how to avoid this ?
We strictly want to show error message immediately if the given condition is true else display the else section(table).

Thanks,
Anupama


    

 
Best Answer chosen by Anupama@28
Anupama@28Anupama@28
I found the solution,
I have added one more if tag to check if the list is empty as below.
Not sure how does it matters but it worked.
 
<aura:if isTrue="{!v.bNoRecordsFound}">
    <aura:if isTrue="{!empty(v.listProductLines)}">
       <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_info b1" role="alert">
        <!---- NO RECORDS NOTIFICATION MESSAGE ---->         
       </div>
    </aura:if>
</aura:if>
<aura:if isTrue="{!!v.bNoRecordsFound}">
    <aura:if isTrue="{!not(empty(v.listProductLines))}">
             <table>
                   <!---- TABLE WITH DATA --->
             </table>
    </aura:if>
 </aura:if>

 

All Answers

Adilson Arcoverde JrAdilson Arcoverde Jr
Hi,

I would try to run this code:
<aura:if isTrue="{!v.bNoRecordsFound}">
       <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_info" role="alert">
            <span class="slds-assistive-text">Error</span>
            <h2> ERROR MESSAGE </h2>
        </div>
</aura:if>
<aura:if isTrue="{!!v.bNoRecordsFound}">
             <table>
                   <!---- TABLE WITH DATA --->
             </table>
 </aura:if>

Let me know if I can help with anything else. If you find this solution useful, please mark as Best Answer to help others too.

Regards.
Anupama@28Anupama@28
I tired this too... but no luck :(
Adilson Arcoverde JrAdilson Arcoverde Jr
Can you send me your component entire bundle (CMP, controller and helper)?

Regards.
Adilson Arcoverde JrAdilson Arcoverde Jr
Anupama@28,

I can't reach sfdcmonkey.com website. I guess is out for maitenance. Could you send me the bundle?

Regards. 
Anupama@28Anupama@28
I found the solution,
I have added one more if tag to check if the list is empty as below.
Not sure how does it matters but it worked.
 
<aura:if isTrue="{!v.bNoRecordsFound}">
    <aura:if isTrue="{!empty(v.listProductLines)}">
       <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_info b1" role="alert">
        <!---- NO RECORDS NOTIFICATION MESSAGE ---->         
       </div>
    </aura:if>
</aura:if>
<aura:if isTrue="{!!v.bNoRecordsFound}">
    <aura:if isTrue="{!not(empty(v.listProductLines))}">
             <table>
                   <!---- TABLE WITH DATA --->
             </table>
    </aura:if>
 </aura:if>

 
This was selected as the best answer