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

  • Hi Damira, please let us know if this is a Lightning Web Component or an Aura component. – Dan Wareing Nov 11 '19 at 11:53
  • Hi, this is an Aura component. Thank you! – Damira Petrean Nov 11 '19 at 13:47
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.

| improve this answer | |
  • Thank you for your answer. Unfortunately I am not able to use aura:if, as I am setting the columns from the controller. – Damira Petrean Nov 15 '19 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 – Dan Wareing Nov 15 '19 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.