# Modifying table's data binding styles

**URL:** <https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 30, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574 "2023-08-30T18:41:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 30, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574/1 "2023-08-30T18:41:29Z")

</div>

I feel that I have sorted out this problem before but can't remember how.

- I have a session custom property with a query binding returning a dataset.
- I want to change the color of a cell's background based on the value of another cell on the same row.

Can someone give me a pointer on how to do a script transform on the dataset binding?

In a nutshell, how do I convert the dataset into this format?

```auto
{
  "city": {
    "value": "Folsom",
    "editable": true,
    "style": {
      "backgroundColor": "#F7901D",
      "classes": "some-class"
    },
    "align": "center",
    "justify": "left"
  },
  "country": "United States",
  "population": 77271
}

```

Thanks.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [August 30, 2023, 6:47pm UTC](https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574/2 "2023-08-30T18:47:12Z")

</div>

I used this post in the past to change the background color with a transform.

> [@Perspective Table - Invididual Cell Conditional Formatting](https://forum.inductiveautomation.com/t/perspective-table-invididual-cell-conditional-formatting/39371):
>
> Hello everyone. I am having some difficulty with individual cell conditional formatting on the new perspective tables. I am using the script below from another post to apply formatting based upon a cell return. While this works for applying the background colour to the entire row, I need this to be cell specific. I assume I need to make my JSON return more specific/requiring a specific key/value pattern but have not been successful in doing so. Has anyone had luck with this? Ignition Version: …

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 30, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574/3 "2023-08-30T18:52:22Z")

</div>

This may be too magical/meta-programmy/functional for personal tastes; your mileage may vary.

One possible approach would be to break down the transformation operation into a value -\> style decision, per 'cell' in the dataset:

```python
def formatCity(value):
	return {
		"value": value,
		"editable": True,
		"style": {}
	}

def formatCountry(value):
	ret = {
		"value": value,
	}
	if (value == "United States"):
		ret["style"] = {
			"backgroundColor": "#FF0000"
		}
	return ret

metadata = {
	"city": formatCity,
	"country": formatCountry
}

return [
	{
		columnName: metadata.get(columnName, lambda v: v)(value.getValueAt(rowIndex, colIndex))
		for colIndex, columnName in enumerate(value.columnNames)
	}
	for rowIndex in xrange(value.rowCount)
]

```

Disclaimer: I haven't tested this code, so there's a decent chance it doesn't even run. But it might be suitable as a starting point for ideas.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 30, 2023, 9:09pm UTC](https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574/4 "2023-08-30T21:09:58Z")

</div>

> [@josborn](#):
>
> I used this post in the past ...

That's funny. I contributed to that post. I knew I had done this before.

> [@paul-griffith](#):
>
> `for rowIndex in xrange(value.rowCount)`

I'm getting an "Object has no attribute 'rowCount'" error. I can't find the correct syntax on a web search.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 30, 2023, 9:32pm UTC](https://forum.inductiveautomation.com/t/modifying-tables-data-binding-styles/78574/5 "2023-08-30T21:32:49Z")

</div>

The intention is for `value` to be a dataset, as if this were a transform script.
