How do I access data displayed in a table?

I have a table that pulls it's data from a javascript query . My table then has a column for all the returned values in the query. However there is one additional column where it's doing some mapping based on the URL column and is then mapping that data to display what is needed to see in the table.

{{  category_values.value.filter(x => (item.match(/cats=([^&]*)/)[1].split(",")).includes(x.id.toString())).map(x => x.name)  }}

I now want to display those name values in a text field, however since category_values isn't part of the table data, I can't just do something like {{table.selectedRow.category_values}}. I can see the values in the table UI, how can I access that?

Screenshot 2024-04-04 at 4.25.26 PM

Hey there @SGMH

Link to similar topic here Filtered Table Values - #2 by mckenna & here How to get the sum of a column in a table component - #14 by Kabirdas

I have tested that but when I make a JS query that is return myTable.getDisplayedData() it appears to be returning the same data as the myTable's source data. It isn't displaying what is shown in the table. I don't see the category column in the getDisplayedData().

Is there another step needed to make getDisplayedData() work in a JS query?

My only other thought at this point is to change the data structure so the data transformation happens before it is displayed to the table, but that would take a bit of reworking the app.

+1, Facing exact same Issue. I want to get exact Column Name as displayed in the table along with relevant data.
table1.data and table1.getDisplayedData() are not the solution for the above. They don't return in the manner required.

1 Like

Hi there,

Thanks for reaching out to us! I just tried to test this on my end and it seems to work as intended.


Is there something different about my setup here in terms of data query? Please let me know!

Referencing the data in another query worked here as well.

Just tested again and still not working for me. As my first screenshot of the table shows, there's a column named Category that has some words formatted as tags.

Here is my query just to test getting the results of that displayed data

You can see in the data output that it doesn't include the Category column.

Hey @SGMH can you share a bit more about how this table is set up. Is Category a column that is returned in the JS query which populates the table? Or is this a custom column added afterwards?

Just tested table.getDisplayedData() and it seems to work in both cases with dynamically mapped values. If you could share a bit more about your specific setup, I can try and reproduce the issues you are having. Thanks!

Category is a custom column added after the JS Query populates the table. And the values for the Category column are:

Hey @SGMH mind trying this sample app out to see if it works for you? Displayed data returns the correct info here on a custom column and an existing column with data that is different than the source.

If possible would love to get an app export and a couple sample rows of data from your table and category_values so that I can repro.

Thanks!
Custom Column - Displayed Data.json (69.9 KB)

Thanks @joeBumbaca. Your example app was helpful and pointed me to what the issue is! I basically modified your example app as best I could to replicate my actual app to see where the issues lie. The culprit? column id

I noticed the error icon on the columns in my table and it was because the original column and updated categories column were both pulling from the same source. And since both columns had the same ID (which was blank, so it was using the source value of id), table2.getDisplayedData() didn't return all the data as it had duplicated IDs. Once I gave both columns a unique ID, the data now displayed! So yes, the function is working correctly, it was merely a user error that Retool alerted me to and it didn't click to be the source of the problem until now. :man_facepalming: :
table-columns

Thank you all for the help in figuring this out and hope it helps others who might be having a similar experience.

2 Likes

Awesome!! Glad you were able to resolve it, and it's working properly for you!

1 Like