2

I have a lightning datatable and into one column called 'Set Primary Contact' I want to display an icon if the custom field IsPrimaryContact__c has the value TRUE, or a button 'Set primary contact' if the field has the value FALSE.

I managed to display only the button and to disabled it if the IsPrimaryContact__c is TRUE.

enter image description here

Below is the code for this column setting...

 {type: "button", label: 'Set Primary Contact', typeAttributes: {
                    label: 'Set Primary Contact',
                    variant: 'brand',
                    name: 'Set Primary Contact',
                    title: 'Set this contact as Primary Contact',
                    disabled: { fieldName: 'IsPrimaryContact__c'},
                    value: 'Set Primary Contact',
                    iconPosition: 'left',
                    onclick: ''
                }}

Thank you!

Later Edit: This is an Aura component

2
  • Hi Damira, please let us know if this is a Lightning Web Component or an Aura component. Nov 11, 2019 at 11:53
  • Hi, this is an Aura component. Thank you! Nov 11, 2019 at 13:47

1 Answer 1

0

I believe what you're looking for is something like:

<aura:iteration items="{!v.contacts}" var="contact">
    <aura:if isTrue="{!contact.IsPrimaryContact__c}">
        <lightning:icon iconName="action:approval" alternativeText="IsPrimary" />
        <aura:set attribute="else">
            <your-button-component-here>
        </aura:set>
    </aura:if>
</aura:iteration>

For more information on how Aura:If works, please refer to the Salesforce docs here.

2
  • Thank you for your answer. Unfortunately I am not able to use aura:if, as I am setting the columns from the controller. Nov 15, 2019 at 8:28
  • I see. I haven't used Aura for a while, but if it's like LWCs you could set some custom js-controller-side property on the contact, like: ` contact.IsPrimaryContact = true ` in the js controller, and ` <aura:if isTrue="{!contact.IsPrimaryContact}"> ` in the component Nov 15, 2019 at 8:51

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.