Powertable - row selection based on cursor's click / move

Hello Ignition wizards,

I’d kindly like to ask you for help regarding PowerTable. What would be the most ultimate coolest thing: As cursor is being moved across the PowerTable, the rows of the powertable would change colors according to cursor’s position (e.g. cursor is on 10th row, let’s make this row colored differently).

What I’ve done so far is that when user clicks on particular row, it’s being colored differently, but with one drawback - only the cells to the right from the clicked cell on this row are being colored. The cells on the left don’t do anything as can be seen here:

.
The table itself has custom property called highlightedRow. This property is being reseted with propertyChange and configureCell looks as follows:

def configureCell(..parameters here..): 
if selected: 
		self.highlightRow = rowView
	
	if rowView == self.highlightRow:
		return {'background':system.gui.color(250,214,138)}

			
	if selected==False:
		if colView == 5:
			return {'background':system.gui.color(255,255,0,50)}#total: light yellow 
		elif colView in range(6,10):
			return {'background':system.gui.color(244,139,244,60)}  #FV, FT, FU, FJ: pink 
		elif colView in range(10,12):
			return {'background':system.gui.color(149,79,15,90)}  #FI, FG: light brown
		elif colView in range(12,14):
			return {'background':system.gui.color(149,79,15,50)}  #FO, FM: very light brown
		elif colView == 17:
			return {'background':system.gui.color(0,255,0,50)} #niO: light green
		elif colView == 16:
			return {'background':system.gui.color(255,0,0,50)} #iO: light red		
		else:
			return {'background':'white'}

… i know this is not a state of art approach, but did not think of anything better so far. Thanks in advance for the advices.

P.S. mouseMoved() handler does not work as it is not fired with every move of the cursor.

Take care, thank you all in advance.

There are some selection modes you can try out on the power table.

When you allow row selection, but disable column selection, then every cell on the selected row will have the selected flag set to True. So there’s no need for a self.highlightRow variable anymore.

And even if you enable both row and column selection (which would allow selecting a single cell), you can still give a different highlight to the entire row by using the self.selectedRow field on the table.

EDIT: if you want to have it changed on a mouse movement, you can simply set the selectedRow field on the power table on mouse movement. No need for other fields.

1 Like

Hello, Sandred17,

your advice with column selection allowed = false helped me. You deserve a thumbs up :slight_smile: .

I don’t get your advice concerning MouseMovement handler. What code to insert in this handler? I inserted

event.source.selectedRow = y / event.source.rowHeight

… but nothing happens. Selected row still stays the same.

Thank you, take care.

Apparently, the mouseMovement handler only gets exucuted when the mouse enters the component. So that won’t help with your case.

Also watch out for floating point divisions. The regular division in Python will turn your number into a floating point number, which won’t match any row number. You can use the int() function to transform it to an integer.

To get the whole row to highlight,

  1. Set your choice of highlight colour against the Power Table Property ‘Selection Background’

  2. As you have identified, use the configureCell scripting function and target the ‘background’ attribute of the selected cell (which is the entire row).

if selected:
		return {'background': self.selectionBackground}
	elif someotherlogic == 1:
		return {'background': anotherMemoryTag}

With this setup, selecting a row highlights the entire row with a colour already set against the Selection Property attribute on the table. When selecting elsewhere, the cell(s) are filled with the resulting logic from the elif