0

I am quite new in lightning and I need an hint in order to resolve a problem.

What I would like to achieve: in a table component, for each record I would like to see a column with different icon based on the property "TypeName" of the current record.

In order to be more clear this is what I need:

enter image description here

I achieved this result with the following code:

            <th scope="row">
              <div class="slds-truncate" title="type">
                <aura:if
                  isTrue="{!currentRecord.typeName == 'OPENOPPORTUNITY' || currentRecord.typeName == 'LOSTOPPORTUNITY' || currentRecord.typeName == 'OPPORTUNITYWITHORDER' }"
                >
                  <lightning:icon
                    iconName="standard:opportunity"
                    alternativeText="Opportunity"
                  />
                  <aura:set attribute="else">
                    <lightning:icon iconName="standard:orders" alternativeText="Order" />
                  </aura:set>
                </aura:if>
              </div>
            </th>

I would like to avoid the "Hard coded" part of the aura:if by calling a method on the controller that return true is the typeName of the currentRecord is the one I need.

Ma question is, how can I retrieve from the controller the type of the currentRecord or directly the entire currentREcord?

Please keep in mind that there is no event that is firing here, so I don't really know how can I do!

Thanks for the help Folks!

  • A quick suggestion would be to change your typeName values to something that matches the icon typeNames like instead of "OPENOPPORTUNITY" , set the value as "opportunity" - If you can't change the values then check if a runTime conversion is possible . In this case you dont have to do a conditional check using aura:If , all you need to do is to dynamically append the typeName to the lightning:icon's iconName property in the aura:iteration. Each typeName would get automatically associated to its respective icons. – StormBr34ker Aug 13 at 11:15
1

You can't really call a method like that. The typical solution is to provide an additional attribute in your data to determine which way you should go. You can then use the ternary operator in order to determine which icon to show:

var retVal = result.getReturnValue();
var oppTypes = ['OPENOPPORTUNITY','LOSTOPPORTUNITY','OPPORTUNITYWITHORDER'];
retVal = retVal.map(row => (
  { ...row, 
    isOpp: oppTypes.indexOf(row.typeName) > -1
  }
));

Then in your code:

              <lightning:icon
                iconName="{!currentRecord.isOpp?'standard:opportunity':'standard:orders'}"
                alternativeText="{!currentRecord.isOpp?'Opportunity':'Order'}"
              />

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.