I have a primeng table with a dropdown for currency change. The data being in USD and dropdown has different option to update the data to different the currency rate . I have the logic that can update the data to different currency but here I am facing one challenge i.e. whenever I am selecting the currency option I am loosing the original data(i.e) in USD. How to retain the original data ?
Here is the code:
ngDoCheck() {
this.productionTablecopy = [...this.productionTable]; /// creating copy of original data
}
onDropdownChange(event) {
const array = this.productionTablecopy;
if (event.code == 'NOK') {
this.getExchangeRate(array, this.NOK)
}
if (event.code == 'GBP') {
this.getExchangeRate(array, this.GBP)
}
if (event.code == 'EUR') {
this.getExchangeRate(array, this.EUR)
}
if (event.code == 'USD') {
this.productionTable = array; /// get original data again
}
}
getExchangeRate(array, exchangerate) {
this.productionTable = array.map(obj => {
const newObj = {};
Object.entries(obj).forEach(([key, value]) => {
newObj[key] = typeof value === 'number' ? value * exchangerate : value;
});
return newObj;
});
}