How to use Multi-Select Dropdown and filter the Power Table

I'm off tomorrow, so if you haven't figured this out by then, I'll set something up in my test environment to demonstrate a few ways to do this.

I imagine that you will need to get the column as a list to make it useful for querying, which means you would have to script the query on the selectedLabels propertyChange event.

The script would look something like this:

'''
Written for the script editor of the multiselect dropdown's propertyChange event handler
'''

# If and only if the selectedLabels property of the multiselect dropdown changes
if event.propertyName == 'selectedLabels':
	
	# Get the labels as a list
	labels = event.source.selectedLabels.getColumnAsList(0)
	
	# Create a parameterized query query and match the number of parameters to the number of labels
	query = "SELECT * FROM KoroitSamples WHERE KoroitSamples.[Instrument] IN (%s)" % ', '.join('?' for item in labels)
		
	database = #The database name will need to be defined
	
	# Run the query and assign its result to the data property of the power table
	# Change this path to the relative path of the power table
	event.source.parent.getComponent('Power Table').data = system.db.runPrepQuery(query, labels, database)

That script looks proper by my eyes, but full disclosure: I'm not where I can test code at the moment.

2 Likes