Setting variables dynamically

Hi everyone,
I have a value in a table which is linked to a database column.
I need to be able to change it from another component
I don't see how can I use temporary variables to achieve this, because the cell is already linked to a source column in the database and I cannot make it a "consumer" of the correspond temporary variable.
Is it possible in some way?
Otherwise, maybe can I change the table.changesetArray from other component? I don't really mind losing synchronization of the column values in my retool table as long as the database is updated correspondly.

More background on the case:
I have a text input column in a table, say row_comments, which is linked to a DB column. When I click on a row, an informative modal is opened with the row contents (i.e a "focus" to a single row, as there are many columns for each row)- and I need to be able to set the text input as well from the focused view.

Thanks

If I am understanding your process correctly, you click a row on a table and open a modal with the row values. You then want to change the values in this modal and then have the changes update the underlying table. Is this correct?

If so, you can achieve this by setting up an editable form in the modal. When you make changes to the data, it will have to be submitted to the underlying database and the table will need to be refreshed to show the change.

If you are simply looking for a way to edit a cell from a component, the table doesn't really support that. You'd want to change the cell value manually and then "save" the changes which is functionally what the modal form would be doing.

ETA:

I do not believe this is yet possible with how the tables are functioning.

1 Like

I agree with pyrrho. If you do not want to update the value stored in the database, and lose changes when you refresh / revisit the page could be:

  1. create a column that displays a dynamic value
  2. create a copy of the database dataset that you can freely manipulate to set as the table's data source like const new data = {{formatDataAsArray( <originalData>) }}

Hi pyrrho and thanks for the answer
You understood the case correctly. But the reason I wanted to use changesetArray is because the table is pretty heavy, and takes about 30 seconds to be loaded after a refresh.
Therefore I aimed to update the database only after several changes (I'm doing multiple edits one after another, sometimes 20-30 times, and I want to update once when finished or by bulks)

Maybe, I can have a temporary variable to manually hold the "changeset" of the input fields being updated through the modal, and each edit I'll append the latest value to it (i.e a dictionary that maps table_primary_key->latest text input value), and when running the UpdateTable resource query I'll set the database with either it and the original changesetArray changes?
If it is possible it might serve my use-case. Do you think it can be done easily?

Your thought about holding the data in a temporary variable is a good one. The original table data can be part of the process for making changes by opening the modal for each row, but you can certainly use the submit to append the data. In this case you're building a custom changeSet array and won't need the original table to be editable at all.

The final data in the variable could then be used as the data source for a review table that can (if more edits are possibly needed) be hooked into the same (or similar) modal structure.

Once the review table looks good you can have a button to send the data through to your DB in a final update query using your primary keys and refresh the main (original) table data.

I went for it and it worked properly :slight_smile:
It's pretty useful, I now hold a variable for local changeset (which I can use for future indirect updates) and combine it with the original changeset when updating the db.
The only different is, that I don't see a popup at the bottom of the page for indirect updates:
image
And I didn't find how it is triggered (looks like something builtin a table?).

1 Like

I'm not quite sure I follow this part.

If you're making direct updates then you are submitting them from the original data table? How/Where does the the indirect update data get combined? The pop-up is the Cancel/Save button?

What is the "it" in "how it is triggered" and which table is triggering it?

You right I'll try to clearify more my intentions.
I have that field in the table that I want to edit also from the modal mentioned above (among several more editable fields in the table).
I want to change this fields in "bulks", by that I mean that I send an update query to the database only after multiple edits (and not querying after every change).
The table component have a nice little "Save actions" add-on which shows me the small popup below informing the amount of changes I made - and the save button triggers a query to the database correspondly (with the table.changesetArray data). This add-on doesn't exist in a regular text input field.
So editing multiple fields from the table is easy, I just click that save button when I finish and the update query is set.
Now, say I edit several text inputs from the modal (which is "indirectly" by saving it to a temporary variable) - I would need a separate way to query the database.
I was looking for a way to trigger the table's "Save action" from the modal also.
image

Hope it's clearer now :slight_smile:

Much!

I would recommend that you test out a button that is used to take the variable of all the indirect changes you have made that can be used to trigger a duplicate of the same Save action event handler that the original tables uses. They should have the same structure so you should be able to run the new query using the variable data in place of the changeSet array.