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’}
else:
{‘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.

alright

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?

#NAMES
“Batch Element ID”,“Material”,“Target Amt.”,“Actual Amt.”,“Manual”,“Duration”
#TYPES
“str”,“str”,“D”,“D”,“B”,“D”
#ROWS”,“12”
“AdxDisch1”,“Water Reducer”,“172.0”,“171.0”,“false”,“22.602579”
“AdxFill1Bottle1”,“Water Reducer”,“172.0”,“171.0”,“false”,“18.863748”
“AggDisch1”,“Sand”,“14784.0”,“14720.0”,“false”,“91.8762834”
“AggDisch2”,“Sand”,“14784.0”,“14720.0”,“false”,“77.7972088”
“AggFill1”,“Sand”,“14784.0”,“14720.0”,“false”,“16.0651466”
“AggFill3”,“1”,“12660.0”,“12680.0”,“false”,“21.0685922”
“AggFill4”,“3/8”,“4750.0”,“4720.0”,“false”,“36.7500414”
“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”
“WtrDisch1”,“Water”,“240.6381”,“236.5”,“false”,“81.4018504”
“WtrFill1”,“Water”,“240.6381”,“236.5”,“false”,“93.449272”

You want the query that populates it?

SELECT
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
WHERE
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’}
else:
{‘background’: ‘White’}

if self.data.getValueAt(rowIndex,‘Batch Element Id’) == ‘AggFill1’ & self.data.getValueAt(rowIndex,‘Duration’) > 22:
{‘background’: ‘White’}
else:
{‘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'}
	else:
		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”))