In order to make a dynamically changing CRUD view I’ve been trying to make columns editable dynamically.
I’ve managed to dynamically fill the columns prop, but I’m running into a strange issue. Even though I make sure my list/array filled with my modified JSON objects contain the correct values, it populates the columns prop with however many of the exact same JSON object, effectively only showing one of my columns, always the last.
Here is my code in case anyone spots something obvious:
import json
#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 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'"+tableName+"'"
columnNames = system.db.runPrepQuery(queryGetColumns)
#construct and fire a query to return the column with identity
queryGetUnique ="SELECT name FROM sys.identity_columns WHERE OBJECT_NAME(object_id) = ?;"
argList = [tableName]
uniqueColumn = system.db.runScalarPrepQuery(queryGetUnique, argList)
print 'unique = '+uniqueColumn
#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:
propsColumns.append(columnJSON)
propsColumns[i]['field'] = column
#if the column ins't the identity column make it editable
if column != uniqueColumn:
propsColumns[i]['editable'] = bool(1)
else:
propsColumns[i]['editable'] = bool(0)
print propsColumns[i]['field']
print propsColumns[i]['editable']
#counter + 1
i = i+1
#populate columns prop
self.getSibling("Table").props.columns = propsColumns
Does anyone have an idea what might be causing this or is this simply a bug?