Greetings. I have a sql query that is returning performance values that I have linked to a Perspective Table. I'm trying to apply conditional formatting on a column that is hidden on the table but in the dataset called "Perf Int". On the Table.props.cells.style.backgroundColor property I've set the following Expression:
This is changing the background color to green which is the first value, but when it falls below 95 it remains green. I'm sure that I need to loop it through the table, and I believe I'm just calling the column heading but I'm not sure how to bridge the gap between what I've got and where I need it to be at. Can anyone assist?
I think what's happening with your expression is that your evaluating the first row of the dataset; in your screenshot its >=95 therefore all rows will be green.
You can achieve what you want by reading this post:
Hey man I appreciate the reply. Unfortunately Iâm still learning my way through all of this. Should I attach this as a scripting transform on the data itself, or should I use this as an expression on the row color background binding?
I appreciate the help but I told you I'm very green at this and learning. I'm getting a script error on line 5 and as far as I can tell my indents are correct?
def transform(self, value, quality, timestamp):
"""
Transform the incoming value and return a result.
Arguments:
self: A reference to the component this binding is configured on.
value: The incoming value from the binding or the previous transform.
quality: The quality code of the incoming value.
timestamp: The timestamp of the incoming value as a java.util.Date
"""
output_json = []
style_red = {"backgroundColor": "#FFCCCC"}
style_green = {"backgroundColor": "#CCFFCC"}
for row in range(value.getRowCount()):
row_object = {}
row_value = {}
row_style = {}
for col in range(value.getColumnCount()):
row_value[value.getColumnName(col)] = value.getValueAt(row, col)
row_object['value'] = row_value
if value.getColumnName(col) == 'Perf Int':
if value.getValueAt(row, col) >= '95':
row_style = style_red
elif value.getValueAt(row, col) <= '94':
row_style = style_green
row_object['style'] = row_style
output_json.append(row_object)
return value
Set as dataset, it returns the values fine with no errors, but it also doesnât apply the color with the script transform haha. I told you man Iâm green!
When I drop the quotes, I still get the following script error set on JSON return, and when I put to dataset it goes through without the background changing still:
Bingo, got it my man, thank you for the help. I had changed back to JSON return, that was my issue at the end. Return dataset, and then return json on the script transform!