Clear tables before a new query is run to repopulate them with new data

I have a series of tables that get populated based on the entry of an single email. The value of the email input is used in a series of Queries, both JS and Firebase/Firestore tables. There are various parent/child relationships where rows are found, or not found, and the results populate the tables.

  1. As soon as I start the search I want to clear the data from all the tables as it is no longer valid.
  2. In fact if there are no records returned for a given query based on the new email, the table rows from the last query (a different email) remain.

Hey @George_B! I’m not 100% sure I follow your situation, but I think I can help answer a few questions to get you on the right track.

For your first question:

Retool includes a JS function to set the table data table1.setData() (see docs here), which you can use to clear the table data by passing in an array with an empty object like this: table1.setData([{}]). You should set this up as a “Run JS Code” query and then trigger it according to your needs.

For your second question:

This is a bit more complex. I recommend setting up a transformer to handle the required logic and then return the correct data for the table. Then you can set the data property of the table to {{transformer1.value}} and it will populate correctly based on the situation.

1 Like