Hello! I'm fairly new to retool and not very strong in JS
I have a table component that allows the user to input values in some columns.
The goal is to view a calculated value in a custom column that i created (with a formula: new_custom_column = fee_initial_value * (index_current_value / index_initial_value).
-
I would like for the user to be able to click on a button that will trigger a calculation and show the calculated value in new_custom_column. This is before the data is inserted into the database, its just for the user to be able to view the calculated value.
-
Details:
I added a button to the canvas and created an event handler to it that triggers a 'run script'. I think I'm missing something because this hasn't worked
See below script:
let updatedData = [...table31.data];
table31.changesetArray.forEach(change => {
let rowIndex = change.index;
Object.keys(change).forEach(key => {
if (key !== "index") {
updatedData[rowIndex][key] = change[key];
}
});
updatedData[rowIndex].currentFeeValue = updatedData[rowIndex].fee_initial_value * (updatedData[rowIndex].sale_index_current_value / updatedData[rowIndex].sale_index_initial_value)
});
table31.setData(updatedData);
console.log("Updated Table Data:", updatedData);
return updatedData;
Thanks!