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

Hello,

Similar to this thread 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.

	# 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.

	
	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

image

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.

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.

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

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

	# 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.

You could use one of Swing's native .repaint() methods to avoid using a binding refresh. (Just feed it the component's actual size.)

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

1 Like

Pretty sure that does a lot more than repaint.