# Highlight Table Row

**URL:** <https://forum.inductiveautomation.com/t/highlight-table-row/62006>\
**Category:** Ignition\
**Tags:** ignition80, vision\
**Created:** [July 18, 2022, 2:30pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006 "2022-07-18T14:30:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 2:30pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/1 "2022-07-18T14:30:57Z")

</div>

I am sure I am just missing how this works but I cannot for whatever reason figure out how to highlight rows in a table. I am using a Table component in a Vision window, this table contains data from a Named Query and I need to be able to highlight all the rows within the table when a specific column (say col4) contains the name of the currently logged in user. I know I could accomplish this using the Table Customizer and Background Color Mapping if the column was a numeric value, however it is text.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [July 18, 2022, 2:40pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/2 "2022-07-18T14:40:24Z")

</div>

are you opposed to using a Power Table?

It will allow you to do this via it’s `configureCell` extension function.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/af9499bd6d42cece6b97c90400be095c948f4435.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2fefdf5af53606a2b2d97b5c33a95e249bc4a60f.png)

You would just need to modify the code in `configureCell` to meet your criteria

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 2:41pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/3 "2022-07-18T14:41:45Z")

</div>

A Power Table should work too, I’ll give it a try and update.

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 3:25pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/4 "2022-07-18T15:25:36Z")

</div>

Im not sure if I am missing something but it seems as though this should work? I just need the row to change background colors when the logged in user matches a name on the table.

```auto
if colName == "username" and value == system.client.user.username:
	return {'background': 'yellow'}
else:
	return {'background': 'white'}

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/5 "2022-07-18T15:27:55Z")

</div>

> [@jwilliams](#):
>
> `system.client.user.username`

This doesn't exist. Try [system.security.getUsername()](https://docs.inductiveautomation.com/display/DOC81/system.security.getUsername).

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 3:45pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/7 "2022-07-18T15:45:45Z")

</div>

That doesnt quite seem to work either but I do see my mistake with using system.client.user.username. This is the updated code however it still rejects it, underlining the first return as outside function. I feel as though I am missing something in order to make this work properly or that there is an easier way to accomplish this.

```auto
userName = system.security.getUsername()
user = system.user.getUser("", userName)

if colName == 'username' and value == user.get('firstname'):
	return {'background': 'yellow'}
else:
	return {'background': 'white'}

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2022, 3:49pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/8 "2022-07-18T15:49:31Z")

</div>

Why are you using `system.user.getUser()`? Just compare to their actual user name.

If you absolutely have to compare to their given name, compute it outside this extension function and place it in a string custom property. Then the often-called `configureCell` only has to compare to the custom property.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [July 18, 2022, 3:50pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/9 "2022-07-18T15:50:27Z")

</div>

This should work to highlight the entire row where the username matches the logged in user:

```auto
if self.data.getValueAt(rowIndex, 'username') == system.security.getUsername():
	return {'background': 'yellow'}
else:
	return {'background': 'white'}

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17be72b102d14c50f0256a038c446eb4096db747.png)

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 4:00pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/10 "2022-07-18T16:00:01Z")

</div>

Is your binding on the component scripting configureCell? Where you right click the Power Table and choose Scripting?

I am not sure what I am doing differently than you have.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/0/70ab4e3311a77ec4717b9346eac38ab1c0ff2832.png)

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [July 18, 2022, 4:02pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/11 "2022-07-18T16:02:32Z")

</div>

highlight lines 34-37 and press tab one time and it should work

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 4:03pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/12 "2022-07-18T16:03:57Z")

</div>

Wow okay did not know that tab there mattered. Thank you!

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [July 18, 2022, 4:05pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/13 "2022-07-18T16:05:26Z")

</div>

Yep, they’re all underneath the method definition at the top! so they need to be tabbed over one time

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [July 18, 2022, 4:07pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/14 "2022-07-18T16:07:06Z")

</div>

Never even noticed that up there, I’ll keep that tab spacing in mind for future scripting!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2022, 4:22pm UTC](https://forum.inductiveautomation.com/t/highlight-table-row/62006/15 "2022-07-18T16:22:44Z")

</div>

The indentation is necessary for extension functions and custom methods and most scripts in Perspective. Events that do not show `def` at the top should not be indented.
