# Adding columns to table from dynamic data

**URL:** <https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 16, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312 "2024-10-16T13:48:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [October 16, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/1 "2024-10-16T13:48:55Z")

</div>

Hello!

I´ve got a script that get data from the query and depending on multiselect filter get more columns...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e4f330cecbc467042fcc84cb7c2d0656633c2010.png)  
with this build in the script

```python
   # Build queryBrutal part dynamically from assetData and descriptions
	    queryBrutal = ", ".join(["Asset.{} AS \"{}\"".format(field, field) for field in descrips])
	

```

and {queryBrutal} in the query

I´m getting more data but the table doesn´t show more columns.

I would like to know how to add columns while I adding data dinamicaly?

this is how I tried to update the table component, but gives a component error in the table  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e4420ee49b09e2a60fc76ba0b12ca5f18118ca19.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2d93f429f083df09eef1e8769eca36882d9f38f3.png)

```python
   table_component = self.parent.getChild("TabContainer").getChild("TablaInventario")
	        if table_component is not None:
	            table_component.props.data = dataset
	            
	            # Manually update the columns property based on the dataset
	            column_headers = dataset.getColumnNames()
	            new_columns = []
	            for header in column_headers:
	                # Create column configurations for each new column
	                new_columns.append({"field": header, "header": header})
	            
	            # Set the columns property to the new columns
	            table_component.props.columns = new_columns

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 16, 2024, 2:30pm UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/2 "2024-10-16T14:30:51Z")

</div>

Bind the `columns` property to your dataset then build the column configuration from this.  
A dataset even contains data type information so you can configure the columns accordingly.

But frankly I'd approach the whole thing differently.  
Query the whole table, configure the columns however you want, then switch each column's `visible` property based on whatever you use to select columns in your UI.  
This avoids the need to rebuild your query dynamically, and also the need to re-query your db every time the user decides he wants to hide or show a column.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [October 16, 2024, 2:33pm UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/3 "2024-10-16T14:33:42Z")

</div>

> [@pascal.fragnoud](#):
>
> Query the whole table, configure the columns however you want, then switch each column's `visible` property based on whatever you use to select columns in your UI.  
> This avoids the need to rebuild your query dynamically, and also the need to re-query your db every time the user decides he wants to hide or show a column.

Yes, this idea seem much more straightforward.

I will try your first solution and If don´t get any output try the second one.

Thanks Pascal!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 16, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/4 "2024-10-16T14:34:36Z")

</div>

Why not just go for the second one directly ? It's simpler et faster to implement.

edit: It appears some French snuck its way into that post. Can you spot it ?

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [October 16, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/5 "2024-10-16T14:34:53Z")

</div>

Yes, you right, let you know later how it´s going, thanks

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [October 17, 2024, 8:38am UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/6 "2024-10-17T08:38:46Z")

</div>

Ok, I added a binded Expression to the visible property of each column to the dropdown I´m using like:

```python
if(indexOf({.../Flex_Nivel_Expand/Dropdown_1.props.value}, 'Ubicacion') >= 0, true, false)

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/449074f53c5cdc184177abde4b41401e218599f5.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/a/ea2c02f5312e883a6559bcb1ed264f99364db878.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 17, 2024, 11:37am UTC](https://forum.inductiveautomation.com/t/adding-columns-to-table-from-dynamic-data/97312/7 "2024-10-17T11:37:57Z")

</div>

You don't need the `if (expression, true, false)`, `expression` is enough.
