Access custom columns in JS query

How can I access custom column key and values in JS query?

Use case: I added a custom column namedfoo with value foo? Is there a way to reference this custom column name and value in JS query?

Hi @alisher :wave: typically custom columns are accessed using "Custom Column" and then the custom column number, so, for instance: table["Custom Column 1"] does that work?

Hi @Kabirdas: table returns undefined if though I do I have a custom column added.

Let's say I have some data in the table. Looks like I can access this data with table.displayedData but it does not give me the custom columns and values.

Is there a workaround ?

Ahh my mistake I was thinking of the records in table.recordUpdates can you describe your use case a little further? How are you looking to use your custom columns?

Let's say we have some data coming from our api. Say customer data which has id, payAmount. itemWeight. We add a custom column Value to Weight ratio. Then, we would like to add download all data button. Currently, the custom download functionality on the table only allows users to download the first paginated result set, not all data set.
.
So I was thinking I would write a script that loops through all results of the data including custom column. Is that possible?

I see, after doing some digging it looks like you'll have to recalculate those values in your script when creating the downloadable data :confused:

@Kabirdas thanks for your support. For table component, it will be great to add a property let's say table.tempData which references all column keys and values in the displayed table including custom columns as currently displayed on the frontend. Something to consider for the future :slightly_smiling_face:

This is actually something we're planning on taking a look at! There's no timeframe or guarantee for it making it in but I'll pass your feedback along. If you're interested you might also want to make a post this as a feature request so that it can get more visibility there.

Still a problem July 2022
Screen Shot 2022-07-30 at 1.09.09 PM

1 Like

Here's the answer I got from Retool support:

"You should be able to access the data in your custom column with table.columnMappers['Custom Column n'] where n is whatever number of custom column you need to reference."

I've implemented it in one of my apps and it works!

1 Like

Hey folks! Just want to post a quick update here for anyone who may not have seen it that table v2 now has a getDisplayedData() function which allows you to see any currently displayed date in your table, including custom columns!

The function is async so in a JS query you'll want to use something like const displayedData = await yourTable.getDisplayedData(). That should return your data as an array of objects that includes any custom columns and respects filtering/sorting!

1 Like