# Perspective fill in table with values and styles

**URL:** <https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901>\
**Category:** Ignition\
**Tags:** perspective, scripting, ignition80\
**Created:** [November 23, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901 "2020-11-23T18:45:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 23, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/1 "2020-11-23T18:45:58Z")

</div>

So the documentation says I should use a dataset to fill in the table, can I put a style in that data set as well? If not should I run through the table twice, once to create the dataset and then again to set the styles of each object in the data? I was told to use styles for row color and that would be applied to each cell.Thx, Jake

---

<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:** [November 23, 2020, 7:30pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/2 "2020-11-23T19:30:38Z")

</div>

The generally recommended approach is to retrieve your data at the top level of the binding (via query, HTTP binding, whatever) and then use a script transform - you can loop through the result rows and add a style key as appropriate. Take a look at this thread for some inspiration; it's a bit more complicated than you might need (supporting per-column cell styling) but should be an inspiration:

> [@Perspective Table - Invididual Cell Conditional Formatting](http://forum.inductiveautomation.com/t/perspective-table-invididual-cell-conditional-formatting/39371/4):
>
> A maybe more maintainable variation, if you ever intend on adding other columns you need to style: def cc\_msval(v, r, c): style\_orange = {"backgroundColor": "#F7901D"} style\_green = {"backgroundColor": "#00AA00"} return { "value": v.getValueAt(r, c), "style": style\_orange if v.getValueAt(r, c) \< 95 else style\_green } transforms = { "CC\_msval": cc\_msval } return [ { value.getColumnName(col): transforms.get(value.getColumnName(col), lambda v, r, c: v.getValueAt(r, c))(v…

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 23, 2020, 7:52pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/3 "2020-11-23T19:52:14Z")

</div>

So that looks pretty cool. The data comes from tags so as far as I know there’s no short cut, just have to build it out. I have the styles in the project so I’m assuming I can just do something like styles.white or whatever. Seems like I need to go through once and build the tables values and then style them with another pass.

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 23, 2020, 9:30pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/4 "2020-11-23T21:30:09Z")

</div>

So do I need to loop through twice, just want to confirm?Thx, jake

---

<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:** [November 23, 2020, 10:26pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/5 "2020-11-23T22:26:24Z")

</div>

Well, that would depend on exactly what you’re doing. You mentioned bringing in tags, but how, exactly? If you’re using scripting it should definitely be possible to add style references without a second loop (although a second loop is not likely to be a performance bottleneck - it’ll all happen on the gateway).

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 23, 2020, 10:48pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/6 "2020-11-23T22:48:17Z")

</div>

So I have like 15 udt’s and about 500 units. The udt’s are for a type of unit, and groups of units and such. This was all fleshed out in vision years ago and being migrated to perspective. When you log in it takes the login, usually customer, and builds out a table with only that logins units. The table has unit number, customer, location and voltage. The line will be a color based on the units status, a tag within each of the udt’s. We are constantly adding, deleting and moving units so there’s really nothing I can set in stone.Thx, jake

---

<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:** [November 23, 2020, 11:46pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/7 "2020-11-23T23:46:45Z")

</div>

Ah, okay, so this is housed in some dataset somewhere? If so, then, yeah, you’ll probably want your top level binding to be direct to that dataset, and then use a script transform to go through it and build out your inline styles.

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 24, 2020, 4:57pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/8 "2020-11-24T16:57:50Z")

</div>

It’s not housed anywhere. There’s a tag with comma separated values I use split on to get the unit numbers. Those unit numbers have a tag in their udt that has the status I use to color the row, along with the location company and the volts that I fill in the row values with.

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [November 24, 2020, 7:19pm UTC](https://forum.inductiveautomation.com/t/perspective-fill-in-table-with-values-and-styles/40901/9 "2020-11-24T19:19:35Z")

</div>

So I saw some code for rows creating objects with values and styles, this seems the best way. How do add this to the table, just single dimension array of objects sent in as a dataset?Thx, jake
