Control table column order with dynamic query

Hi all. I have a query which returns a dynamic number of columns (dates in this case). I'm basically building a pivot table.

Tables appear to remember the placement of columns. Say my first query returns this:
2021-01-01
2021-02-01
2021-03-01
2021-04-01

If I then change the query to include a date within those dates, the table adds it as a column at the end, even if in the JSON it's in the right sequence

2021-01-01
2021-02-01
2021-03-01
2021-04-01
2021-01-10

I have tried using 'dynamic column settings' and have been successful in things like renaming columns, but am unable to change the order.

Is there anything I can do? Happy to consider:

  • Something that completely resets the table as it's always correct the first time

  • hand-crafting a javascript snippet to re-order the columns, maybe setting column index or similar

  • javascript to move an individual column that wasn't in the table previously.

  • Delete and recreate a table? but don't think this is practical

  • Return a 'synthetic column header' as the first row of my query, but that's a bit rubbish.

Any ideas? Retool team help?

Thanks!

Hey domjammoo, happy to help here 😁 As you suggested, it looks like a hand-crafted JS transformer on your query could be a workaround for your use case. I am looking into whether there is a better way to do this in Retool and will keep you posted!

Thanks everett. In terms of what the transformer would do, though, is there a way to programatically control the order of the columns? As I mentioned, the query output is in the correct order, it's just that the table column order doesn't change when the query output changes

Hey domjammoo,

I'm sorry to say that it looks like my first response was too optimistic. Our table components "remember" the ordering of columns and it is not possible to dynamically change the column order as a result :cry:

It looks like the only potential workarounds here are quite impractical:

  • Manually create a new table component populated with sorted data each time you need to add a column.
  • Create your own custom component (if you have access that feature on your current plan) that allows you more control over the order of your columns.

I apologize for my initial misleading response—I wish I had better news for you :pensive:

Would you mind if I changed this post from a 'How Do I' to a 'Feature Request' so that other users who are interested can more easily chime in on this?