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:
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?