Populate a table component with the contents of a table which I select from a list of my tables from my database

Hello,

I am trying to populate a table component with the contents of a table which I select from a list of my tables from my database:

SET @PREPARE_SQL=0;
SET @TABLE_NAME = ({{listoftables.selectedRow.Tables_in_test}});
SET @QUERY = CONCAT('SELECT * FROM ', @TABLE_NAME);
PREPARE stmt FROM @QUERY;
EXECUTE stmt;

So when I click a table on the list on the left I want it to populated the table component on the right with the contents of my database table, and regenerate column see image below

I cant get the columns to regenerate when I click through different tables on the left though

Any advice?
Thanks,
H

Hi Hugh!

This should work on our Legacy Table component.

It does seem like our new table doesn't regenerate columns quite as well, but I'll file a ticket internally and keep this thread updated!

1 Like

Hi Victoria,

Thank you for this, yes we need to have this functionality in the table so we will use the legacy table for now, but it would be great if the new table also had this functionality, the toolbar at the bottom with the filter bar etc.

Thanks,
Hugh

Definitely understood! All things we're working on :slight_smile:

1 Like

Great thank you!

Of course! Thank you for adding your +1s. Helps us know what's important!

I'm also interested in this. The legacy table did a great job of responding to changes in the underlying datasource with regard to columns.

The new table is amazing from a UX perspective and definitely looking forward to converting. Our use case is a 50+ column database that users select a small subset of columns to be displayed. It's an app for data exploration, so there isn't a lot of consistency in the columns they select and they change all the time.

IMO an optimal solution would be to have the "Regenerate Columns" available as a "Control Component" event. It's understandable why this isn't around in the new table but having the option for the rare cases it is important would be perfect.

Is it possible there's a way to trigger this with JS? I've run into tons of stuff in the past where it wasn't in the UI or autocomplete yet, but it could be run anyway.

I got around this using the new "Tags" column. I use one "tags" column to hold the values for several columns (these are actually accurately described as tags).

Here's a GPT prompt I used to generate a sample query and I was able to make this dynamic in javascript.

"In a mongodb aggregate pipeline, I am trying to merge two fields "Agent Name" and "Team Leader" (which are strings) into a single array titled 'Tags'. Can you write me an aggregation pipeline step to accomplish this?"

[
// First add the fields to a new object
{
$addFields: {
tags: [
{$ifNull: ["$Field1", ""]},
{$ifNull: ["$Field2", ""]},
]
}
},
// Then Merge the fields of the new object
{
$project: {
tags: { $ifNull: [{ $concatArrays: ["$tags"]}, []] }
}
}
]

When I export, I still project the fields I needed normally (columnar), so it exports normally - it's just not displaying them in the table. This actually turned out pretty well.