Powertable dynamic custom dropdown

Hello,

My assistant has been beating the stick at this for a few days and I’ve figured it out this morning, and we have found nothing on this forum about this. End up to be simple, but you need to know some facts (dataset vs pydataset, self vs event.source and List vs Tuple)

I’ve decided to post it to help others

How I got it to work is to create a project function that create the list of tuples from a dataset:

project.dd script

def ddTable(dtaList):
	
	dtaList = system.dataset.toPyDataSet(dtaList) ##Change dataset to PyDataSet
	dtaList2 = [] #creating the List of tuple to be returned
	
	for row in dtaList:
		dtaList2.append( (row[0], row[1])) ## appending the tuple to the list
		
	return dtaList2

In my case the datasets (dtaCol1, dtaCol2) are a RootContainer Custom Property. The powerable is on the RootContainer too. If your dataset is a custom property of the powertable, just lose the ‘.parent’ in my call. And rename Col1, Col2 , dtaCol1 and dtaCol2 to what ever your powertable Columns and Datasets are. And add or subtract column as much as you need. In my case I have 2 powertable columns with a dropdown each.

So the powertable configureEditor’s Script calls the function like this


def configureEditor(self, colIndex, colName):

	if colName == 'Col1':
		return {'options': project.dd.ddTable(self.parent.dtaCol1)}
	elif colName == 'Col2':
		return {'options': project.dd.ddTable(self.parent.dtaCol2)}