Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How do I get the column names of a table widget?

Issue

I am having trouble getting an array with the column names from a Table widget in Appsmith. I tried using the property "tableColumns" but it doesn't seem to exist in the newer version of the Table widget. I asked for help in the forum and was given a workaround using "columnOrder" instead. However, I learned that internal properties might change over time, so there is a feature request to add a new property called "tableHeaders".

Resolution

To get an array of column names in a Table widget, there are different properties to use depending on the version of the widget.

For older versions, use the following code:

{{Table1.tableColumns.map((item)=> item.id)}}

For newer versions, use this code:

{{Table1.columnOrder}}

If neither property is available or if there are changes to the widget in the future, a workaround is to use the following code to get the column names:

{{Object.keys(Table1.tableData[0])}}

It's important to note that any properties not exposed through the autocomplete are internal properties and subject to change over the course of the widget lifespan. If there are changes in the future, it may be necessary to re-write any code using these properties. A new feature request has been created to add a new tableHeaders property to the autocomplete in the Table widget.