Highlight Row in Power Table based on search query result

I’m trying to search through a column of recipe names in a MSSQL table for a specific string value. If the search returns a match, I want to highlight/goto the row in the table. I think I have the first part, but the next part I can’t seem to figure out.

Script on button

  • Grab the values from the Text Fields.
    RECIPENAME = event.source.parent.getComponent(‘RecipeNameSearch’).text

  • Use those values in the SEARCH RECIPE Named Query.
    system.db.runNamedQuery(“SEARCH RECIPE”, {“RECIPENAME”:RECIPENAME})

Named Query

SELECT * FROM RecipeExample
WHERE RECIPENAME = :RECIPENAME;

Format your code with the </> button so it is readable. If the table is already filled with the contents of your recipe data, then you don’t need to run another query. Simply search the table data for the recipe name you are looking for.

lookup = event.source.parent.getComponent("RecipeNameSearch").text
table = event.source.parent.getComponent("Power Table")
recipes = table.data.getColumnAsList(table.data.getColumnIndex("RECIPENAME"))
ndx = None

for i,recipe in enumerate(recipes):
	if recipe == lookup:
		ndx = i
		break

if ndx is not None:
	table.selectedRow = ndx
else:
	system.gui.warningBox('Recipe not found')

Thanks! That is exactly what I needed! I am very new at this and appreciate the fast and concise answer. Solution marked.

1 Like