# Dynamically creating columns prop for table, all headers are the same

**URL:** <https://forum.inductiveautomation.com/t/dynamically-creating-columns-prop-for-table-all-headers-are-the-same/29152>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 17, 2019, 11:50am UTC](https://forum.inductiveautomation.com/t/dynamically-creating-columns-prop-for-table-all-headers-are-the-same/29152 "2019-10-17T11:50:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RadicalRumin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/radicalrumin/32/11543_2.png) [@RadicalRumin](https://forum.inductiveautomation.com/u/RadicalRumin)\
**Post date:** [October 17, 2019, 11:50am UTC](https://forum.inductiveautomation.com/t/dynamically-creating-columns-prop-for-table-all-headers-are-the-same/29152/1 "2019-10-17T11:50:38Z")

</div>

I had an old script that successfully created the dictionaries inside of the columns prop to dynamically set the editability. Today I tried doing something similar, dynamically setting the headers. I put these extra lines of code in the same part of the script as where I set editability, but for some strange reason it changes all headers to the last alias retrieved from the database.

the code:

```auto
import json
import copy

	#clear the columns prop
	self.getSibling("Table").props.columns = []
	#get the table name from the custom prop on the root
	tableName = self.parent.custom.tableName
	#construct and fire a query to return the columns in the table.
	queryGetColumns = "Select columnName FROM MasterData WHERE tableName = '"+tableName+"'"
	columnNames = system.db.runPrepQuery(queryGetColumns)

	IsModifiable = "Select MasterData.modifiable from MasterData where columnName = ? AND tableName = ?"
	#make an array/list to fill with JSON objects
	propsColumns = []
	#load in the JSON format for columns prop
	columnJSON = json.loads(self.getSibling("Table").custom.columnFormat)
	#counter
	i = 0
	#for every column fill propsColumns with a JSON object
	for row in columnNames:
		for column in row:
			print i
			params = [column, tableName]
			columnHasDropdown = system.db.runScalarPrepQuery("SELECT hasDropdown FROM MasterData WHERE tableName = '"+tableName+"' AND columnName = '"+column+"'")
			modifiable = system.db.runScalarPrepQuery(IsModifiable, params)
			propsColumns.append(copy.copy(columnJSON))
			propsColumns[i]['field'] = column
			#if the column ins't the identity column make it editable
			if modifiable:
				propsColumns[i]['editable'] = bool(1)
			else:
				propsColumns[i]['editable'] = bool(0)

			if columnHasDropdown:
				alias = str(system.db.runScalarPrepQuery("SELECT alias FROM MasterData WHERE tableName = '"+tableName+"' AND columnName = '"+column+"'"))
				(propsColumns[i]['header'])['title'] = alias
				

			#counter + 1
			#print propsColumns[i]['header']['title']
			i = i+1
	#populate columns prop
	self.getSibling("Table").props.columns = propsColumns

```

I used the console to check what was being writting into the header with prints, but those are all in order.

Does anyone have an idea what could be causing this?
