Power Table Color

I have a power table that I am trying to change colors for each row based on their values in the Duration column.For instance WtrFill1 over 50 turn red, AggFill1 over 22 turn red and so on for each row.Thank you in advance.

Use the Component Scripting Extension Function “configureCell”.
There is example text there to get you started.
You will need to use colIndex to get values of interest and return a dictionary with color/font attributes you want.
Don’t get too complex with your script here because it runs for every row/column in the table.

Can you give me an example of what it would look like? I can’t see to get it to work.

this should get you on the way^^

enter scripting of the powertable and go to configureCell:

if you want the whole row, something like this should do it:

if self.data.getValueAt(rowIndex,'int') < 1:
		return {'background': 'green'} 
	elif self.data.getValueAt(rowIndex,'int') > 2:
		return {'background': 'red'}

I see that, but that is by column mine needs to by the row because each has a different set point.So I tried this but it doesn’t work,

if self.data.getValueAt(‘WtrFill1’, ‘Duration’) >50:
{‘background’: ‘RED’, ‘foreground’:‘Black’}
{‘background’: ‘WHITE’, ‘foreground’:‘Black’}

getValueAt needs rowindex, a number, not a name as first argument
do you want the whole row or only the first column to change color?

try changing wtrFill to rowIndex

I would like the whole row to change color. But my table doesn’t always have the same number of items because each batch is different. The columns stay but rows change every batch.


if self.data.getValueAt(rowIndex,'BatchElementId') == 'WtrFill1' &  self.data.getValueAt(rowIndex,'Duration') > 50:
		return {'background': 'red'} 
if self.data.getValueAt(rowIndex,'BatchElementId') == 'AggFill1' &  self.data.getValueAt(rowIndex,'Duration') > 22:
		return {'background': 'red'}

It gives me this error.

Parse error for extension function “configureCell” SyntaxError: (“no viable alternative at input ‘&’”, (’ ', 46, 66, “if self.data.getValueAt(rowIndex,‘BatchElementId’) == ‘WtrFill1’ && self.data.getValueAt(rowIndex,‘Duration’) > 50:\n”))

ah might be just one & instead of two &&
you can also use and

i edited it.

also im not sure that BatchElementId is your first column’s name, you should double check that as i didnt see that bit of your code :stuck_out_tongue:

BatchElementid is the first column. now I get

SerializationException: Error invoking [ColorStateTable]com.inductiveautomation.factorypmi.application.components.util.ColorStateTable@6864a5d0.setStates({})
caused by IllegalArgumentException: argument type mismatch

Ignition v8.1.0 (b2020110211)
Java: Azul Systems, Inc. 11.0.7

is the duration column of type number?

Yes , but it comes in as a double is that the problem?

it shouldnt be, could you show your code and copy the clipboard of your datatable here?

“Batch Element ID”,“Material”,“Target Amt.”,“Actual Amt.”,“Manual”,“Duration”
“AdxDisch1”,“Water Reducer”,“172.0”,“171.0”,“false”,“22.602579”
“AdxFill1Bottle1”,“Water Reducer”,“172.0”,“171.0”,“false”,“18.863748”
“CemDisch1”,“Cement D”,“5730.0”,“5720.0”,“false”,“50.8892642”
“CemFill1”,“Cement D”,“5730.0”,“5720.0”,“false”,“41.1181694”
“MixerDisch1”,“Cement D”,“5730.0”,“5720.0”,“false”,“101.9993426”

You want the query that populates it?

la.LinkElementId AS ‘Batch Element ID’,
mr.MaterialName AS ‘Material’,
mr.Target AS ‘Target Amt.’,
mr.Actual AS ‘Actual Amt.’,
mr.IsManuallyAdjusted ‘Manual’,
la.ActualRuntime AS ‘Duration’

FROM loads ld
JOIN materialrequests mr ON mr.LoadRowId=ld.RowId
JOIN linkelementactivityrecords la ON la.MaterialRequestRowId=mr.RowId
JOIN plants pl ON pl.PlantId=ld.PlantId
JOIN linkelements le ON le.LinkElementId=la.LinkElementId AND le.PlantRowId=pl.RowId
ld.PlantId= :Plant AND
ld.Rowid= :Batch
ORDER BY la.LinkElementId

no thats fine^^ the script you sued to color i do tho

if self.data.getValueAt(rowIndex,‘Batch Element Id’) == ‘WtrFill1’ & self.data.getValueAt(rowIndex,‘Duration’) > 50:
{‘background’: ‘red’}
{‘background’: ‘White’}

if self.data.getValueAt(rowIndex,‘Batch Element Id’) == ‘AggFill1’ & self.data.getValueAt(rowIndex,‘Duration’) > 22:
{‘background’: ‘White’}
{‘background’: ‘White’}

	if (self.data.getValueAt(rowIndex,'Batch Element Id') == 'WtrFill1') & (self.data.getValueAt(rowIndex,'Duration') > 50):
		return {'background': 'red'}		
	elif (self.data.getValueAt(rowIndex,'Batch Element Id') == 'AggFill1') & (self.data.getValueAt(rowIndex,'Duration') > 22):
		return {'background': 'red'}
		return {'background': 'white'}

seems it was doing a bit difficult with the and, it needed some brackets around it
also you forgot return and you should use elif cuz else it will slow down your table a lot

with the return I get this error

Parse error for extension function “configureCell” SyntaxError: (“mismatched input ‘return’ expecting INDENT”, (’ ', 47, 1, “\treturn {‘background’: ‘red’}\t\t\n”))