I have a data table and I'm trying to follow the manual to change the row colors based on values. When using this script.
def transform(self, value, quality, timestamp):
# Ensure the value is a list (your case: list of dicts)
#if not isinstance(value, list):
# return value
styledRows = []
for row in value:
# Copy the original row to avoid mutating it
newRow = dict(row)
# Get the 'Inspected' value (defaults to False if missing)
inspected = row.get("Inspected", False)
# Apply row-level style
newRow["__style__"] = {
"backgroundColor": "#d4edda" if inspected else "#f8d7da", # light green / red
"color": "#155724" if inspected else "#721c24", # dark green / red text
"fontWeight": "bold"
}
styledRows.append(newRow)
return styledRows
This script is a transform on a query binding with a json type. It only shows 1 row when i apply it and does not change the row colors at all.
Any help would be appreciated
Before going into any other issues with this (probably LLM generated) script, try fixing your indentation. You must use consistent indentation in Python; your script as posted is alternating tabs and spaces, so what code is actually running is not easy to determine:
def transform(self, value, quality, timestamp):
# Ensure the value is a list (your case: list of dicts)
#if not isinstance(value, list):
# return value
styledRows = []
for row in value:
# Copy the original row to avoid mutating it
newRow = dict(row)
# Get the 'Inspected' value (defaults to False if missing)
inspected = row.get("Inspected", False)
# Apply row-level style
newRow["__style__"] = {
"backgroundColor": "#d4edda" if inspected else "#f8d7da", # light green / red
"color": "#155724" if inspected else "#721c24", # dark green / red text
"fontWeight": "bold"
}
styledRows.append(newRow)
return styledRows
1 Like
Took you code and applied it. It no longer only shows one row but still no color change. Where is the error here?
Again, just taking the first thing I see:
__style__
is nothing (an LLM hallucination) - you need to return a value at the style
key:
1 Like