# Highlighting a row in a table based off of a columns value in a Power Table

**URL:** <https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [May 11, 2024, 10:41pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273 "2024-05-11T22:41:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [May 11, 2024, 10:41pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/1 "2024-05-11T22:41:00Z")

</div>

I am needing to Highlighting a row in a table based off of a columns value in a power table. I am trying to use a for loop but can't seem to get the script to work. As anyone had any luck with something like this? This is the script I am trying to make work

```python
import system
	
data = self.data
data2 = event.source.parent.getComponent('Power Table').data
# 'data'table and 'data2' is power table
for row in range(data2.getRowCount()):
    reject_number = data2.getValueAt(row, 'RejectNumber')
    for row2 in range(data.getRowCount()):
        ingot_number = data.getValueAt(row2, 'IngotNumber')
        if reject_number == ingot_number:
            event.source.parent.getComponent('Table').style.rowBackground = 'Red'

```

---

<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:** [May 11, 2024, 11:18pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/2 "2024-05-11T23:18:08Z")

</div>

Vision Power Table's don't have styles like that. That's Perspective.

Implement the `configureCell()` extension functions. That gets called whenever java Swing needs to paint cells, separately for every cell that is visible (at least). The method can look up the row data for the cell in question to return the desired adjustments to the normal painting operation.

Similar recent topic:

> [@Power Table OnMouseClick Cell Color Change](https://forum.inductiveautomation.com/t/power-table-onmouseclick-cell-color-change/90150/6):
>
> You cannot directly change the cell color from the mouse event. You must store your styling information in a custom property (perhaps another dataset with the same dimensions as your table data). The mouse event can only update that custom property. The configure cell method is called automatically by the component whenever java swing needs to "paint" that cell. Have that method look up the desired color in the custom property and return that. Changing a custom property is one of the trigg…

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [May 12, 2024, 3:55pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/3 "2024-05-12T15:55:23Z")

</div>

so how would I go about setting it up correctly? Adding a custom property as a dataset and referencing that?

---

<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:** [May 12, 2024, 10:13pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/4 "2024-05-12T22:13:29Z")

</div>

If your main dataset has the information needed to decide the styling, simply reference it directly.

Show a sample dataset and describe the styling result you want.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [May 12, 2024, 10:34pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/5 "2024-05-12T22:34:40Z")

</div>

If the IngotNumber and RejectNumber match, then I want to highlight the row red in the Power Table

This data comes from the Data binding of the Power Table

```python
IngotNumber AvgHeight 
26258 3.0672528743743896 (This one matches) this row should be red
26257 3.2045392990112305
26256 3.179182529449463
26255 3.177241086959839
26254 3.1401920318603516
26253 3.257405996322632
26252 3.1032402515411377

```

This data is in the custom property of the Power Table called RejectData

```python
RejectNumber DateTm
26258 Sat May 11 23:15:19 CDT 2024 (This one matches)
26251 Sat May 11 23:11:19 CDT 2024
26240 Sat May 11 23:10:37 CDT 2024
26218 Sat May 11 23:09:33 CDT 2024
26215 Sat May 11 23:07:21 CDT 2024
26212 Sat May 11 23:07:02 CDT 2024
26209 Sat May 11 23:06:44 CDT 2024

```

---

<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:** [May 12, 2024, 11:34pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/6 "2024-05-12T23:34:45Z")

</div>

Ok, then your `configureCell` extension method would look something like this:

```python
def configureCell(self, value, textValue, selected, rowIndex, colIndex, colName, rowView, colView):
	rejects = self.RejectData.getColumnAsList(0)
	if self.data.getValueAt(rowIndex, 0) in rejects:
		return {'background': 'red'}

```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [May 15, 2024, 12:12pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/7 "2024-05-15T12:12:17Z")

</div>

This what I tried but it didn't seem to work.

```python
	import system
	from java.awt import Font
	data = self.data #Data from Power Table
	rejectData = self.RejectData #Reject Data from Power Table custom property
	def configureCell(self, value, textValue, selected, rowIndex, colIndex, colName, rowView, colView):
		rejects = self.RejectData.getColumnAsList(0)
		if self.data.getValueAt(rowIndex, 0) in rejects:
			return {'background': 'red'}

```

---

<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:** [May 15, 2024, 1:12pm UTC](https://forum.inductiveautomation.com/t/highlighting-a-row-in-a-table-based-off-of-a-columns-value-in-a-power-table/90273/9 "2024-05-15T13:12:48Z")

</div>

The `def configureCell(...)` is supplied by the extension method editor. You cannot put anything above that line, nor indent it.

Make sure you are making the actual extension method look like what I supplied.

If you need more functionality, including imports, create a project library script function (preferably not called `configureCell`) and delegate to it.
