# Change row color of table based on a value of the row

**URL:** <https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 23, 2020, 12:23pm UTC](https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548 "2020-01-23T12:23:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![petar.zurzevic](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@petar.zurzevic](https://forum.inductiveautomation.com/u/petar.zurzevic)\
**Post date:** [January 23, 2020, 12:23pm UTC](https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548/1 "2020-01-23T12:23:29Z")

</div>

Hi, im using a table in perspective that shows the results of a query, im trying to change color of the row based on the value of a field in the table, is it possible?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [January 23, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548/2 "2020-01-23T15:13:10Z")

</div>

Yes you will need to use a transform script and build the styles object for each row.

---

<div class="post-metadata">

**Author:** ![winbetho](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@winbetho](https://forum.inductiveautomation.com/u/winbetho)\
**Post date:** [February 24, 2020, 12:22pm UTC](https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548/3 "2020-02-24T12:22:15Z")

</div>

Can you give me an example of howt get the value i want to transform from the dataset?

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [March 22, 2023, 8:59pm UTC](https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548/4 "2023-03-22T20:59:38Z")

</div>

Bind the data property to a named query. My original SQL statement was the following:

```auto
SELECT WorkstationID, WorkstationTypeName, WorkstationName FROM Workstations;
```

Set the return format as JSON.

Modify the transform code posted below to match your specific application.

```auto
def transform(self, value, quality, timestamp):
	new_list = []
	
	# Iterate over each dictionary in the original list (results from database table)
	for item in value:
	    # Create a new dictionary for the converted JSON
	    new_dict = {
	        "WorkstationID": item["WorkstationID"],
	        "WorkstationTypeName": item["WorkstationTypeName"],
	        "WorkstationName": {
	            "value": item["WorkstationName"],
	            "editable": True,
	            "style": {
	                "backgroundColor": "#F7901D",
	                "classes": "tables/rowIsDecommissioned"
	            },
	            "align": "center",
	            "justify": "center"
	        }
	    }
	    # Append the converted dictionary to the new list
	    new_list.append(new_dict)
	    
	return new_list
```

As you loop through each item in value (the original SQL results) you can check on various values and then modify the backgroundColor as needed.

I was looking for the answer also to this question and eventually had ChatGPT spell it out for me in the example above (with some slight modifications since Ignition takes care of certain tasks in the background). I hope this helps others.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 22, 2023, 9:20pm UTC](https://forum.inductiveautomation.com/t/change-row-color-of-table-based-on-a-value-of-the-row/31548/5 "2023-03-22T21:20:00Z")

</div>

Actually, your solution would only change the background color for an individual cell (`WorkstationName`) - not a row. We've already had multiple threads which convey how to do so, [including this one here](https://forum.inductiveautomation.com/t/perspective-table-cell-color/50047) which covers how to do both cells and rows.
