I am new to Retool and I am facing some problems. I created a table from JSON using a variable (eg, variableTableJSON). Now I want to save changes a specific column which is editable. I created Add on -> Save action -> Run script and wrote the following codes there. But it it doesn't work. Can anyone please help me? Thanks in advance.
{{ variableTableJSON.value = [...variableTableJSON.value,...table1.changesetArray] }}
table1.refresh()
Rgds.
Sudip
2 Likes
Welcome to the Forum Sudip!
1 Like
welcome. You should use setIn or setValue instead of = to set the value of variable. and {{ }} in the script block is not need.
variableTableJSON.setValue ([...variableTableJSON.value,...table1.changesetArray]);
table1.refresh();
here is the doc of variable The Temporary State object | Retool Docs
1 Like
Thanks a lot!!! I shall try and inform you.
Rgds
Sorry, changes in the table isn't saved. Moreover table1.refresh(); reset the table. I commented this line. But still it's not saved.
Thanks for your help
Sudip
Hello, more detail? You read the data in the query right? and save it to variableTableJSON, then refer it with {{variableTableJSON.value}} in table data source?
I think you are write your first app.
here is a docs for your refer
https://docs.retool.com/apps/web/quickstart
you also can export app to json to us to check, thanks.
or maybe this topic is helpful for you.
[image]
I'm trying to Update database rows via the table Widget (table_orders). I've set a couple of columns to be editable, and set the "Add-ons Save Action" to run "updateRowTable1" Query that I'm trying to build via GUI mode. This Query filters by "id" key with value corresponding to the currently table selected id ({{ table_orders.selectedRow.id }}) and the tries to update all 4 editable fields (status, comments, etc) with values {{ table_orders.selectedRow.status }}.
When I edit a field …
Ok, thank you. BTW, my latest codes added new records.
Trying more ...
1 Like
yes, you can try it with retool database
Finally I am able to solve this problem with following codes:
let tempData = variableTableJSON.value
table1.changesetArray.forEach(changedRow => {
tempData = tempData.map(tempRow => {
if (changedRow.id === tempRow.id) {
return {
id: tempRow.id,
field_type: tempRow.field_type,
replace_formula: changedRow.replace_formula
}
} else {
return tempRow
}
})
})
variableTableJSON.setValue(tempData)
table1.refresh();
Thanks!
3 Likes