I got a chance to play with this a bit. OrderedDict gets reverted to an unordered object when you write it to the data property (even though I was sure it worked before-- ah well), so no joy there.
But, as you should be modifying the props.columns property anyway (as I believe has also been mentioned before), this is a short example of what works.
testTable_2024-06-11_1534.zip (9.3 KB)

Script on button:
sampleHeaders = ['col1', 'col2', 'status']
sampleData = [['a', 'b', 0],
['c', 'd', 1],
['e', 'f', 2]
]
sampleDataset = system.dataset.toDataSet(sampleHeaders, sampleData)
#------------------------------------------------------------------
from copy import deepcopy
from collections import OrderedDict
bgColors = {0 : '#00FF00', # Green
1 : '#FFFF00', # Yellow
2 : '#FF0000', # Red
}
blankColSetting = {
"field": "",
"visible": True,
"editable": False,
"render": "auto",
"justify": "auto",
"align": "center",
"resizable": True,
"sortable": True,
"sort": "none",
"filter": {
"enabled": False,
"visible": "on-hover",
"string": {
"condition": "",
"value": ""
},
"number": {
"condition": "",
"value": ""
},
"boolean": {
"condition": ""
},
"date": {
"condition": "",
"value": ""
}
},
"viewPath": "",
"viewParams": {},
"boolean": "checkbox",
"number": "value",
"progressBar": {
"max": 100,
"min": 0,
"bar": {
"color": "",
"style": {
"classes": ""
}
},
"track": {
"color": "",
"style": {
"classes": ""
}
},
"value": {
"enabled": True,
"format": "0,0.##",
"justify": "center",
"style": {
"classes": ""
}
}
},
"toggleSwitch": {
"color": {
"selected": "",
"unselected": ""
}
},
"nullFormat": {
"includeNullStrings": False,
"strict": False,
"nullFormatValue": ""
},
"numberFormat": "0,0.##",
"dateFormat": "MM/DD/YYYY",
"width": "",
"strictWidth": False,
"style": {
"classes": ""
},
"header": {
"title": "",
"justify": "left",
"align": "center",
"style": {
"classes": ""
}
},
"footer": {
"title": "",
"justify": "left",
"align": "center",
"style": {
"classes": ""
}
}
}
dataIn = system.dataset.toPyDataSet(sampleDataset)
colNames = dataIn.columnNames
blankRow = {col : {'value': None, 'style' : {}} for col in colNames}
dataOut = []
colSettings = []
for i, row in enumerate(dataIn):
newRow = deepcopy(blankRow)
for col in colNames:
newRow[col]['value'] = row[col]
newRow[col]['style'] = {'backgroundColor' : bgColors[row['status']]}
dataOut.append(newRow)
self.getSibling("Table").props.data = dataOut
for col in colNames:
colSetting = deepcopy(blankColSetting)
colSetting['field'] = col
colSettings.append(colSetting)
self.getSibling("Table").props.columns = colSettings