Hey I have figured out how to start to do some conditional formatting the table component in perspective. I am using a named query binding to the data property and have selected JSON, and have added a transform script.
In my script I am able to set the style for the cell of a row, but would like to actually change the style of the whole row.
Here is what I have so far:
def transform(self, value, quality, timestamp):
style_yellow = {"backgroundColor": "#FFFF8F"}
style_green = {"backgroundColor": "#AFE1AF"}
style_orange = {"backgroundColor": "#F28C28"}
style_white = {"backgroundColor": "#FFFFFF"}
newData = []
# Iterate over each row in 'value', which is the original result set
for row in value:
# Within the row, iterate over each column
for col in row:
# Create a variable to store the contents of the original "cell"
cell = row[col]
if col == "Revision":
if cell == "FOR APPROVAL":
# Create a dictionary containing the original value, and some styling information
row[col] = {"value": cell, "style": style_yellow}
elif cell == "FOR CONSTRUCTION":
row[col] = {"value": cell, "style":style_green}
elif cell == "FOR REVIEW":
row[col] = {"value": cell, "style":style_orange}
else:
row[col] = {"value": cell, "style":style_white}
# Add the modified row to the list we initialized earlier
newData.append(row)
return newData
Any ideas?