Specify table data source dynamically based on select component value

I have specified several data queries, each linked to a different data resource (in my case, dynamoDB tables).

By adding a table component and specifying the Data field to be
{{ queryName.data.Items }}, as expected, the table is populated with data from the specified data resource.

But now instead of having the table statically linked to a single query and data resource, I would like to have this linkage dynamically selectable using a select component named select1 for example, with option values matching my query names.

But {{ [select1.value].data.Items }} doesn't work even though select1.value does evaluate to "queryName".

Is this possible? Or is there another approach to dynamically switching a single table component between different queries / data resources?

Have you tried using the new "Split button":
image
Each option can have a different event handler: a different query!
here's the link to the documentation: Split Button | Retool Component Library
I hope it helps (:

Thank you very much. Using the Split Button, I am able to associate a different control component : setData with each option, which indeed allows me to switch data sources on each click. Tremendous!

I do observe that since the Split Button only supports click events and not change events, it requires two operations to execute. First select (change) the option, then click the button. After clicking the button, the setData brings in the new data via the new query.

One opportunity for improvement would be to allow the user to configure each event as either a click or a change event. If I could add a change event, once the option was selected, the setData would immediately execute without the additional requirement of clicking the button.

1 Like

Maybe you could try using the "Segmented control" instead?
image

You can assign them some values to use them in the event handler later on:
image

Event handlers:
image