Hello everyone,
I am trying to change the color of a cell in a perspective table based on the value of two columns.
Currently, I am doing this in the script mapping of data property binding. The script is:
output_json = []
style_red = {"backgroundColor": "#D9000099"}
style_green = {"backgroundColor": "#9ED23E"}
style_yellow = {"backgroundColor": "#F4F03D"}
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 col == 'process_value':
if value.getValueAt(row,col)>=value.getValueAt(row, 'low_limit') and value.getValueAt(row,col)<= value.getValueAt(row, 'high_limit'):
cell_style= style_green
elif value.getValueAt(row,col)>value.getValueAt(row, 'high_limit'):
cell_style= style_red
elif value.getValueAt(row,col)<value.getValueAt(row, 'low_limit'):
cell_style= style_yellow
cell_object['style']=cell_style
row_object[col]=cell_object
output_json.append(row_object)
return output_json
However, this code cannot be generalized as I have multiple views and I would like to have this script in a single location that I can call for each time. For colors also I would like to use style.
I was thinking to use the combination of message handlers and style but I would like to know your suggestion that? what would be the best way to approach this?
Thank you!