- My goal: I need to approve/decline notifications (rows in the table). The status of each row is defined by a tag with multiple options, and we need to set it to "approved" or "rejected".
- Issue: row actions running custom script do not affect table contents or the changeset. There seem to be no way to programmatically alter the table's content in general?
Hi @pavelgur,
You are correct, unfortunately that is a limitation of Retool. No one can programmatically write to the changeset or 'mutate' the table data.
You can have a query write to your DB with the status that the user has selected from the tag options. But I would need more details to help further with next steps.
Hello @pavelgur,
If I understand your question correctly, I believe I’ve implemented something similar to what you're describing—merging query data with modified input. I’ll double-check my notes tomorrow, but I believe I approached it using a transformer. The table's value would be set to the result of this transformer.
Within the transformer, I pulled in the query data and compared it to the table’s changeset. If there were any modifications, I merged the query data with the changeset so the table would reflect the updates accordingly.
I’ll follow up once I can confirm the syntax, but I’m confident there’s a solution here.
Thank you @rh25170!
Very curious to see your solution. There are definitely some options in terms of work arounds, just depends on what the goal is and what trade offs the user would like to make.
Instead of programmatically trying to alter the table's contents to reflect which rows have had a status value changed. You could use a form component that would post to the DB that is the table's data source to update a status column to have "approved" or "rejected".
Limitation leads to confusion since after saving changes to the table, and changesetArray is cleared, the table reverts back to it's original state. So I need to refresh the whole table (takes seconds) just to alter one row. And that is the problem that trivial table manipulations are so hard to do
Ahh ok I see, thank you for the additional details.
The pattern for best practices with tables is that the component displays data that has been fetched, and that on any changes to the table's data in the frontend, a query should run to save these changes in the backend and refetch the table.
If fetching the whole table's data takes too long, have you tried paginating the table so that it can load in faster and only display a couple rows at a time?
changesetArray
and changesetObject
are readonly in the v2 table, they won’t automatically reflect programmatic updates.
The other work around would be to have a variable set to the query's data, then set this var as the table source. Then you can use variable.setValue()
to mutate the variable based on changes from the changestArray/obj and the table will automatically update to reflect these changes.
But you will have to figure out how to thread the changes made into the data.
An example of a JS query that would do this to update a status to complete would be something along the lines of
const newData = [...tableStartData.value];
newData[rowIndex] = { ...newData[rowIndex], status: "Completed" };
tableStartData.setValue(newData)
Where instead of hardcoding in status: "Completed" you would have double curlies and also need to grab the row Index to correspond to which row you want to update the key-value pair for.
My apologies, been rather busy. I tried to find where I did this and wasn't quite able to find it. I tried to recreate it to no avail, but I definitely know it's possibly, just takes some patience to figure it out.
No worries!
If you find the table with this set up let us know.
From my understanding, the best option is save changes to DB and re-load the table. If the table's reload query is too long then pagination is one options to get the rows back quicker.
With the other option being to make many edits, then save them all at once to the DB. This risks the temp updates that are stored in the table's changeset array being lost by networking timeouts or page refreshes but allows for making lots of rapid small changes.
@pavelgur is the issue that you are trying to use row actions running custom scripts to create changes/updates to the table's changeset? Does using the tables editable row feature to switch tags to "approved" or "rejected" not possible for your use case?