I am trying to apply dynamic icons to LWC data table using "cellAttributes". In my @wire method, I am running "ForEach" on fetched records, checking condition and assigning icon accordingly. So far it does not work and datatable does not display any icon. Please advice what I am doing wrong? Ideally into Status field, I should see Icons dynamically based on "Cathegory__c" field value. Is this possible to achieve somehow?
Here is my code:
const COLUMNS = [
{ label: 'status', cellAttributes:
{ iconName: { fieldName: 'priorityicon' }}},
{ label: 'Scenario', fieldName: 'Cathegory__c', },
];
export default class NbeFullListOnObject extends LightningElement {
@wire(FetchRecos)
wiredRecos({error,data}){
if(data){
this.record = data;
//loop through the list of contacts and assign an icon based on the rating
this.record.forEach(item => {
let iconObj = {...item};
if(item.Cathegory__c === 'value1'){
iconObj.priorityicon = "action:priority";
}else if(item.Cathegory__c === 'value2'){
iconObj.priorityicon = "action:bug";
}else{
iconObj.priorityicon = "action:call";
}
});
}
}