Set a row in a table to selected based on a value in a row

I am trying to set a row in a table to selected when a column in the row is equal to 2. Does anyone have an idea of how I can achieve this?

This worked for me when executed from a button.

dataIn = event.source.parent.getComponent('Table').data
# Get column values
colData = list(dataIn.getColumnAsList(dataIn.getColumnIndex('ColName')))

# Find first occurence of the value 2
rowIndex = colData.index(2)

# Set the row to the found index
event.source.parent.getComponent('Table').selectedRow = rowIndex
1 Like

Thanks Jordan, that worked perfectly.

My table is on my main window. Do you know how I could run this script on a button on a popup window.

If I understand you correctly, the button to execute the script is in the popup but the table is in the main window?

if that’s the case, this should work if you execute it from the popup button. For simplicity I just modified @JordanCClark 's code.

# Pull reference to Main Window
mainWindow = system.gui.getWindow("MainWindowPathHere") 
# Reference the main table that is located on the main window
mainTable = mainWindow.rootContainer.getComponent("Table_Name_Here")  
#actual path may vary, if the main table in embedded in a group or multiple groups, you will have to add .getComponent("groupname") for each layer

dataIn = mainTable.data
#Get column values
colData = list(dataIn.getColumnAsList(dataIn.getColumnIndex("ColName")))

# Find first occurence of the value 2
rowIndex = colData.index(2)

# Set the row to the found index
mainTable.selectedRow = rowIndex

Also note, if for whatever reason the main window is closed and this script executes, you will get an error from the ‘system.gui.getWindow()’ function.

2 Likes

Thanks Ryan, this works very well.