HTML:
<lightning-datatable
key-field="addon"
hide-table-header
data={addondata}
columns={addoncolumns}>
</lightning-datatable>
JS:
const addoncolumns = [
{ label: 'Add-on Service', fieldName: 'addon',type:'String' },
{ label: 'Price', fieldName: 'price', type: 'Decimal' }
];
addondata;
method(message){
let tempList;
if(this.addondata != undefined)
tempList = this.addondata;
else
tempList = [];
if(this.fridge != message.fridge){
if(message.fridge == true){
tempList.push({"addon":"Fridge/Freezer","price":200});
}
this.fridge = message.fridge;
}
console.log('1'+JSON.stringify(tempList));
if(this.cabinets != message.cabinet){
console.log('second loop'+this.cabinets+message.cabinet);
if(message.cabinet == true){
tempList.push({"addon":"Cabinets","price":200});
}
this.cabinets = message.cabinet;
}
console.log('2'+JSON.stringify(tempList));
console.log('3'+JSON.stringify(this.addondata));
this.addondata = tempList;
console.log('4'+JSON.stringify(this.addondata));
}
Console Results:
First Click (Shows correctly on screen)-
1[{"addon":"Fridge/Freezer","price":200}]
2[{"addon":"Fridge/Freezer","price":200}]
3undefined
4[{"addon":"Fridge/Freezer","price":200}]
Second Click (doesn't show the second row)
1[{"addon":"Fridge/Freezer","price":200}]
2[{"addon":"Fridge/Freezer","price":200},{"addon":"Cabinets","price":200}]
3[{"addon":"Fridge/Freezer","price":200},{"addon":"Cabinets","price":200}]
4[{"addon":"Fridge/Freezer","price":200},{"addon":"Cabinets","price":200}]
Question:
Why the datatable doesn't show the second row (or any subsequent rows after 1) even when this.addondata
carries the correct value?