Hi all,
I am using a table component with data biding to a named query. When using this biding directly, the data shows as expected. Going 1 step further, I added a script transform to change the cell background color based on its value. After this transform, the data columns are showing in, what it seems to me, random order.
Top table is without transform, bottom table with.
Here you can see the script transform used
Thanks in advance!
you should define columns on your table for consistent ordering
1 Like
Tips:
Post formatted code - not pictures of code. (Use the </> button.) That way we can copy and edit in our answers instead of typing it all out again.
Crop screengrabs to relevant portions.
Thanks for the tip,
Here is the code
output_json = []
style_CIP = {"backgroundColor": "#D8BFD8"}
style_Flush = {"backgroundColor": " #B0E0E6"}
for row in range(value.getRowCount()):
row_object = {}
for col in value.getColumnNames():
cell_object={}
cell_style={}
cell_object['value']=value.getValueAt(row,col)
if "material" in col:
if value.getValueAt(row,col)==0:
cell_style= style_CIP # between
elif value.getValueAt(row,col)==1:
cell_style= style_Flush
cell_object['style']=cell_style
row_object[col]=cell_object
output_json.append(row_object)
return output_json
Your script is transforming the data into JSON which, in Python 2.7, does not preserver ordering.
As Victor says, you need to define the field
property of each column in the order to want and that will sort out the problem.
1 Like
Thanks, that solved the problem!
1 Like
Its not json, its just a python array (list) with objects(dicts).
It just looks like json. Json is data parsed into a specific string format. so its a string. This can be decoded back to python (or almost any other langague)
A lot of people on the forum seem to be confused about this xd
Yes, I'm aware of the difference but mustn't have really grasped it properly. As a result I keep forgetting and mixing the terminology. Thanks for the reminder.
no worries, its not rly a big deal
its also igntions fault, somewhere in the bindings they give an option to return it as dataset or as "json".
idk if it actualy returns json, it could be internally, but it gets turned into a python object somewhere along the way