I need some help. I have a perspective table that I want a specific row to flash when the Status column is "Active". For some reason, my transform code is not working. Could someone review it and see what I may be missing? I do know that my "flashingRow" style class works; I have put it into the row's style in the property editor, and I can get all the rows to flash. However, when I try to make it conditional, it doesn't work. I do have rows striped enabled. But I have tried with that disabled as well. Any help would be greatly appreciated.
def transform(self, value, quality, timestamp):
headers = system.dataset.getColumnHeaders(value)
styled_data = []
for rowIndex in range(value.getRowCount()):
row_data = {}
for colIndex in range(value.getColumnCount()):
col_name = headers[colIndex]
row_data[col_name] = value.getValueAt(rowIndex, colIndex)
# Add the row-level 'style' key
if row_data.get("Status") == "Active":
row_data["style"] = {"classes": "flashingRow"}
else:
row_data["style"] = {}
styled_data.append(row_data)
return styled_data
Post a few lines of the data array so we can see what is returned. Maybe add a non-existent class to the else code so we'll get something. e.g., row_data["style"] = {"classes": "nonFlashingRow"}
When you expand the data property and look at data[0] and data[1] what do you see?
Where is your code being applied? Normally we would do a query binding (or similar) on props.data to get the raw data and then run your script in a Script Transform on the original binding. Is that what you are doing?
I would have thought you could simplify your code to something like,
for row in value:
if row("Status") == "Active":
style = {"classes": "flashingRow"}
else:
style = {}
styled_data.append({"value": row, "style": style)
return styled_data
I can not look at the data coming in on data 0 or data 1 since the table is only part of a view. My data is coming in a dataset, could that be a problem? I did try it using a JSON, but it didn't work that way either, but I may have missed something.
Yes, I am using the binding on the table.prop.data using a query to pull the data, then the code I presented is a transform script. I didn't think this would be such a challenge.
I'm almost 100% certain that this is the issue. Datasets don't care for the dict you're providing for the style; it doesn't get set properly. You'll need to convert the dataset to a list of dicts instead
Thank you for your help. This morning, I changed the dataset to JSON and redid the code. Still not flashing.
styled_data = []
for row in value:
if row.get("Status") == "Active":
row["style"] = {"classes": "flashingRow"}
else:
row["style"] = {}
system.util.getLogger("StyledDataLogger").infof("Row: %s", row)
styled_data.append(row)
return styled_data
INFO | jvm 1 | 2025/06/29 08:26:47 | I [StyledDataLogger ] [08:26:47.424]: Row: {"StartOfDownTime":1751203140580,"EndOfDownTime":null,"Duration":0.12,"Status":"Active","style":{"classes":"flashingRow"}} view=Page/PressPage@C, project-name=CDC_MES_1, component=root/DownTime Table, target=props.data
So everyone can see the upstream process, here is the query that I use to pull the data from the table,
SELECT
PressDownTime.StartOfDownTime,
PressDownTime.EndOfDownTime,
CAST(SUM(DATEDIFF(MINUTE, PressDownTime.StartOfDownTime,
ISNULL(PressDownTime.EndOfDownTime, GETDATE()))
) / 60.0 AS DECIMAL(10,2)) AS Duration,
CASE
WHEN PressDownTime.EndOfDownTime IS NULL THEN 'Active'
ELSE 'Complete'
END AS Status
FROM
PressDownTime
WHERE
PressDownTime.PressID = :PressIDPass
AND PressDownTime.StartOfDownTime >= :PressDateRangePastPass
AND ISNULL(PressDownTime.EndOfDownTime, GETDATE()) <= :PressDateRangeFuturePass
GROUP BY
PressDownTime.PressID,
PressDownTime.StartOfDownTime,
PressDownTime.EndOfDownTime;
Right-click on the table's props.data, copy and paste it here as code. We only need a few array entries, so you can truncate it (keeping the closing brackets so that it's valid JSON) to keep the post short.
That's why my post #4 has the line, styled_data.append({"value": row, "style": style)
It shoves the whole row of data down a level into the row's value property. This is necessary whenever you introduce a style. (Examine the data proprty for the default Table component and see how 'Folsom' is handled - although that's just for a single cell.