Ignition 8.0 insert color from the table (row)

How can i insert color (example color red) from the row when the onhand quantity is less than or equal to the buffer level.
Please see reference:

Thank you.

1 Like

If your table is a Power Table then the code below should work:
Extension Function - ConfigureCell

	color = system.gui.color('red')
	rows_to_color = [x for x in range(self.data.rowCount) if self.data.getValueAt(x, 6) <= self.data.getValueAt(x, 7)]
	for x in rows_to_color:
		if rowIndex == x:
			return {'background':color}	

1 Like

Thank you sir. Got it :ok_hand: :ok_hand:


Thanks in advance sir.
Is it possible sir to highlight (red) only the onhand column only? not the whole row?

Hi! I want make a button and need to delete the selected row. So, how should be the code?


color = system.gui.color('red')
rows_to_color = [x for x in range(self.data.rowCount) if self.data.getValueAt(x, 6) <= self.data.getValueAt(x, 7)]
for x in rows_to_color:
	if rowIndex == x and colIndex == 6:
		return {'background':color}
table = event.source.parent.getComponent('Power Table')
deleted_ds = system.dataset.deleteRow(table.data,table.selectedRow)
table.data = deleted_ds


Can you please check this. It’s not working? Also it have defaults some codes. I can’t delete it too…


The default code is ok ( the one in purple) since is a comment.
I just tried the code and it worked.
Check in the console ( Top Menu - Tools - Console ) if it gives you errors.

I don’t seen any error in console. Also I seen some color is changed in your code. Like red, purple and dark black…
But when I typed the code it’s not changing the text color? Maybe why this happens?

It works in me sir.


Is there any idea if i want to filter table by color?
I want only to filter onhand color that is red using dropdown list?

What do you mean by filter the table by color?

You can’t with any of the built-in filters. I’d recommend the full ‘raw’ dataset be in a custom property on the table component, then put your filtered (or unfiltered, if/when you prefer) dataset in the data property.

1 Like

Example: I want to filter the “low” onhand quantity meaning (less than or equal to the buffer which the highlighted color red)

I have a problem with the sample code given…

ConfigureCell: This function runs once for each cell, every time the cell needs to render. This means that for a table with 10 rows and 10 columns, this function will be called at least 100 times (at least once for each of the 100 cells) when the table initializes, or when the dataset is refreshed, etc. This should be taken into account when implementing this function, and any potentially long running code should be avoided.

So this means that for every CELL being processed you are going to build a list of rows, then iterate AGAIN through that list and do stuff and for the multi color example, you can multiply that by 3!

Instead, try:

background = self.background
foreground = self.foreground
colorRed = system.gui.color('red')
colorGreen = system.gui.color('green')
colorYellow = system.gui.color('yellow')

if selected:
    background = self.selectionBackground
    if colName == 'onhand':
        # I Like column names better since they are less likely to change..
        # Of course this is still inefficient but less so than the above examples.
        value1 = self.data.getValueAt(rowIndex, 'onhand')  
        limit1 = self.data.getValueAt(rowIndex, 'buffer')
        if value1 <= limit1:
            background = colorRed
        elif value1 <= limit1 * mul
            background = colorYellow
        elif value1 > limit1 * mul
            background = colorGreen

return {'background': background, 'foreground': foreground}

There is also an impact on the getValue method, so if you are comparing the same thing multiple times… All that inline list building code is cute, but in the case where a routine is called multiple times you will soon finding your tables running REALLY SLOW!!

I’m actually surprised that other very vocal people on the forums didn’t say something before I did.