Newbie & need help! In my db i'm just saving a Key and haven't figured out how to add the scale to display the just the value

  • Goal:

  • In my db schema, we're saving the key of the value that the user saved. In my table component, i want to then map that key to the actual value from it's scale.

  • Steps:

  • Been searching around the forum for the morning and i'm not seeing how to do this... not sure why i can't find it as it feels like it should be a common use case but i'm guessing i'm just not searching for the correct terminology and i am darn new to retool so i'm sure that's definitely a major part of my problem

  • Saw a post about using Transformers and tried to work with that but am struggling to figure it out. Not sure if that is the correct way to go either. Really hopoing someone could point me in the direction of how to do this or provide some help i would be so very grateful.

  • Details:

  • in my table it has keys like 2 (and yes i know the keys should be numbers but i'm working with what i got..)

  • which it then combines with the scale like

  • const GENDER_SCALE = [
    { item: 'Man', id: '0', },
    { item: 'Non-Binary', id: '1', },
    { item: 'Woman', id: '2', },
    ]

  • which when combined should display "Woman"

  • Screenshots:

hacking at it and it looks like i got it to work by doing this but it doesn't feel like the correct way to do it / pattern

in Mapped Value i changed it to:
{{{ 0: 'Man', 1: 'Non-Binary', 2: 'Woman' } [item]}}

which does display the correct value.

Other use case is that some columns are an array of keys that need to be connected to their values, in the pic, Attend services keys

Hacking at with a transformer former and can it it to spit out what i want but not sure how to attach that transformer to the actual column or something like that... When i wire it up with userProfilesTable.selectedSourceRow.attend_services_keys it displays the selected rows value on every row of the table.

Hi, my solution to this is build your query so it gives the fields you want to fill the table with.

Hi @pfunk ,

This is definitely doable! You have a few examples, I'll try to walk through each of them, but I think they can be solved with a very similar approach!

For the gender example, I would create a transformer that returns a map from the id to the item. Your transformer code would be

return {
  '0':  'Man',
  '1':  'Non-Binary',
  '2': 'Woman'
}

Then, when configuring your gender column, set Mapped Value to {{ transformer1.value[item] }}
This is very similar to what you figured out in your second screenshot! Instead of inlining the mapping, you can put it in the transformer.

For your second example of grabbing multiple items from a list, I would do something similar, but your mapped value would need to map over the values. So your mapped value would be something like {{ item.map(serviceKey => transAttendServices.value[serviceKey] }}
This will make the mapped value an array of all the relevant items.
If you want to display it as a list, for example, you could update your mapped value to {{ item.map(serviceKey => transAttendServices.value[serviceKey].join(', ') }}

Hope this helps! Feel free to follow up with clarifications!

Thanks!!! I was able to get it knocked out with a transformer on the query!! I appreciate your time and response!!

2 Likes