# Referencing updated value of 'selectedRows' on Power Table configureCell function

**URL:** <https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [June 6, 2023, 12:42am UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605 "2023-06-06T00:42:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [June 6, 2023, 12:42am UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/1 "2023-06-06T00:42:07Z")

</div>

Hello,

Similar to [this thread](https://forum.inductiveautomation.com/t/what-triggers-configurecell-on-a-powertable/63454) where I am trying to figure out what actually triggers the execution of the Power Table configureCell function.

I have a table with a "State" column, where i want to by default the background color to white (or nothing) if the cell value is "OK" for that column.

If the value is anything other than "OK", i want to provide a colored background to highlight an issue.

```auto
	# Convert rework state number to text.
	# To keep it simple, leave 0 (no changes) as "OK"
	# and anything > 0 (some change made) as "REWORK"
	# Note: White background = '#FFFFFF'
	
	# Set initial style to white background. 
	# Any changes based on other logic after that can be modified / added using standard dictionary access. 
	# ie: rowStyle['stylePropName'] = value
	rowStyle = {'background':'#FFFFFF'}
	
	if rowIndex == 29:
		# Highlight row 0 grey to indicate it is not changeable
		rowStyle['background'] = '#D5D5D5'
	# end if
	
	# Update State column text to translate code into something useful for PTs
	if colIndex == 1:
		if value > 0:
			rowStyle['text'] = 'REWORK'
			rowStyle['background'] = self.rowColor_warn 
		elif value == 0:
			rowStyle['text'] = 'OK'
		else:
			rowStyle['text'] = 'INVALID'
			rowStyle['background'] = self.rowColor_error 
		# end if

	return rowStyle

```

This is all working fine but i then discovered things get a bit weird when you try and **select** a row that has a custom style background. Ideally i wanted the in-build row selection style to be applied in that case, so i added the following code at the end of my script to deal to it, which also works fine.

```auto
	
	if rowIndex == self.selectedRow:
		del rowStyle['background']
	# end if
	
	return rowStyle

```

However the crux of my problem is the **multi-row selection**. This doesn't seem to be in sync with the configureCell updates.

**Selected rows 0, 2, 5:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9c5b2c640faaa462f1df31d29860b14b54e72686.png)

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

But the last row to be selected, index 5, hasn't refreshed the configureCell script to remove the white background. And won't do so until the **next** row is selected.

---

<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:** [June 6, 2023, 1:06am UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/2 "2023-06-06T01:06:29Z")

</div>

Fundamentally, it is a drawing operation called from repaint. It is theoretically possible for it to not be called on non-visible cells, and it can certainly be called multiple times in some repaint scenarios. The code in `configureCell` must not alter any state of the component or you will suffer. It must simply evaluate the content of the cell and its surrounding to guide the **display** of that cell.

Don't do anything else in `configureCell`.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [June 6, 2023, 1:27am UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/3 "2023-06-06T01:27:15Z")

</div>

I don't believe i am changing the state of the component? Unless setting style['text'] to something counts?

EDIT: All i'm wanting is to use the value of 'selectedRow' and / or 'selectedRows' properties to drive the styling of the cells

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [June 6, 2023, 3:21am UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/4 "2023-06-06T03:21:03Z")

</div>

Inspired by the **repaint** comment i added the following to the propertyChange script for when selectedRows changes:

```auto
	# Force table to refresh to re-trigger 'configureCell' event handler
	system.db.refresh(event.source,"data")

```

Not ideal, but the data is bound using cell update, linked to tags, so it shouldn't be taking much effort to update the binding, unlike a massive SQL query or something.

Now when selectedRows changes, i get the repaint straight away to update all rows with the appropriate 'selected row' styling.

---

<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:** [June 6, 2023, 12:24pm UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/5 "2023-06-06T12:24:50Z")

</div>

You could use one of Swing's native [.repaint()](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JComponent.html#repaint(long,int,int,int,int)) methods to avoid using a binding refresh. (Just feed it the component's actual size.)

---

<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:** [June 6, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/6 "2023-06-06T15:42:44Z")

</div>

Or maybe `event.source.table.model.fireTableDataChanged()`; should trigger a repaint without having to reevaluate the binding.

---

<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:** [June 6, 2023, 7:50pm UTC](https://forum.inductiveautomation.com/t/referencing-updated-value-of-selectedrows-on-power-table-configurecell-function/74605/7 "2023-06-06T19:50:46Z")

</div>

> [@paul-griffith](#):
>
> fireTableDataChanged

Pretty sure that does a lot more than repaint.
