Skip to main content
added 295 characters in body
Source Link
Rahul Gawale
  • 12.3k
  • 6
  • 33
  • 70

Ideally we should use a wrapper so that you won't have any unwanted fields on an object while performing DML operations. Like

sObjectWrapper{ sObject: contactObj, attribute1: 'val1', attribute2: 'val2', attributeN: 'valN' }

HereBut here, for the sake of example, I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

Here I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

Ideally we should use a wrapper so that you won't have any unwanted fields on an object while performing DML operations. Like

sObjectWrapper{ sObject: contactObj, attribute1: 'val1', attribute2: 'val2', attributeN: 'valN' }

But here, for the sake of example, I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

added 5 characters in body
Source Link
Rahul Gawale
  • 12.3k
  • 6
  • 33
  • 70

As of now, expressions are not supported in the LWC template. You can achieve this by defining custom properties in the controller only.

Let's assume you have got these data from the wired method, in the wired callback you can configure that properties based on conditions.

Here I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

@wire(getContactList)
wiredContacts({ error, data }) {
    if (data) {
        let newContacts = [];
        for (let index = 0; index < data.length; index++) {
            let contact = Object.assign({}, data[index]);
            
            if(contact.Type){
                if(contact.subType){
                    contact.customType = contact.Type + ' - ' + contact.subType;
                } else {
                    contact.customType = contact.Type;
                }
            }
            
            
            if(dtcontact.IsSomething__c){
                contact.AccountType = 'Customer';
            } else {
                contact.AccountType = contact.RecordType_Name__c
            }
            newContacts.push(contact);
        }
        this.contacts = newContacts;
        this.error = undefined;
    } else if (error) {
        this.error = error;
        this.contacts = undefined;
    }
}

Now as you have defined custom properties based on conditions just use those in the htmll markup.

<tbody>
    <template for:each={contacts} for:item="dt" for:index="indexvar">
        <tr id="datarow">
            <td>{!dt.customType}</td>
            <td>{!dt.accountType}</td>
        </tr>
    </template>
</tbody>

As of now, expressions are not supported in the LWC template. You can achieve this by defining custom properties in the controller only.

Let's assume you have got these data from the wired method, in the wired callback you can configure that properties based on conditions.

Here I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

@wire(getContactList)
wiredContacts({ error, data }) {
    if (data) {
        let newContacts = [];
        for (let index = 0; index < data.length; index++) {
            let contact = Object.assign({}, data[index]);
            
            if(contact.Type){
                if(contact.subType){
                    contact.customType = contact.Type + ' - ' + contact.subType;
                } else {
                    contact.customType = contact.Type;
                }
            }
            
            
            if(dt.IsSomething__c){
                contact.AccountType = 'Customer';
            } else {
                contact.AccountType = contact.RecordType_Name__c
            }
            newContacts.push(contact);
        }
        this.contacts = newContacts;
        this.error = undefined;
    } else if (error) {
        this.error = error;
        this.contacts = undefined;
    }
}

Now as you have defined custom properties based on conditions just use those in the htmll markup.

<tbody>
    <template for:each={contacts} for:item="dt" for:index="indexvar">
        <tr id="datarow">
            <td>{!dt.customType}</td>
            <td>{!dt.accountType}</td>
        </tr>
    </template>
</tbody>

As of now, expressions are not supported in the LWC template. You can achieve this by defining custom properties in the controller only.

Let's assume you have got these data from the wired method, in the wired callback you can configure that properties based on conditions.

Here I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

@wire(getContactList)
wiredContacts({ error, data }) {
    if (data) {
        let newContacts = [];
        for (let index = 0; index < data.length; index++) {
            let contact = Object.assign({}, data[index]);
            
            if(contact.Type){
                if(contact.subType){
                    contact.customType = contact.Type + ' - ' + contact.subType;
                } else {
                    contact.customType = contact.Type;
                }
            }
            
            
            if(contact.IsSomething__c){
                contact.AccountType = 'Customer';
            } else {
                contact.AccountType = contact.RecordType_Name__c
            }
            newContacts.push(contact);
        }
        this.contacts = newContacts;
        this.error = undefined;
    } else if (error) {
        this.error = error;
        this.contacts = undefined;
    }
}

Now as you have defined custom properties based on conditions just use those in the htmll markup.

<tbody>
    <template for:each={contacts} for:item="dt" for:index="indexvar">
        <tr id="datarow">
            <td>{!dt.customType}</td>
            <td>{!dt.accountType}</td>
        </tr>
    </template>
</tbody>
Source Link
Rahul Gawale
  • 12.3k
  • 6
  • 33
  • 70

As of now, expressions are not supported in the LWC template. You can achieve this by defining custom properties in the controller only.

Let's assume you have got these data from the wired method, in the wired callback you can configure that properties based on conditions.

Here I have created two custom properties(customType, accountType) on contact js Object and put the values conditionally in those

@wire(getContactList)
wiredContacts({ error, data }) {
    if (data) {
        let newContacts = [];
        for (let index = 0; index < data.length; index++) {
            let contact = Object.assign({}, data[index]);
            
            if(contact.Type){
                if(contact.subType){
                    contact.customType = contact.Type + ' - ' + contact.subType;
                } else {
                    contact.customType = contact.Type;
                }
            }
            
            
            if(dt.IsSomething__c){
                contact.AccountType = 'Customer';
            } else {
                contact.AccountType = contact.RecordType_Name__c
            }
            newContacts.push(contact);
        }
        this.contacts = newContacts;
        this.error = undefined;
    } else if (error) {
        this.error = error;
        this.contacts = undefined;
    }
}

Now as you have defined custom properties based on conditions just use those in the htmll markup.

<tbody>
    <template for:each={contacts} for:item="dt" for:index="indexvar">
        <tr id="datarow">
            <td>{!dt.customType}</td>
            <td>{!dt.accountType}</td>
        </tr>
    </template>
</tbody>