# PowerTable dropdown dynamic

**URL:** <https://forum.inductiveautomation.com/t/powertable-dropdown-dynamic/47072>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [May 25, 2021, 6:01am UTC](https://forum.inductiveautomation.com/t/powertable-dropdown-dynamic/47072 "2021-05-25T06:01:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [May 25, 2021, 6:01am UTC](https://forum.inductiveautomation.com/t/powertable-dropdown-dynamic/47072/1 "2021-05-25T06:01:51Z")

</div>

I have a power table

```auto
if colName=='DefectType':	
 query="select Code,Name from RubberDefect"
 DefectType=system.db.runQuery(query,'MaluProduction')
 return {'options': [(row[0], row[1]) for row in DefectType]}

```

In my database I have two column  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28805255d89f665b3d19db4b9a10c148cf35fa68.png)  
I current can use the upside logic show the Chinese word in the dropdown list.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/9/194ad249246aae6b8fca3952bab7a2be045439ce.png)

when I selected, the English word will exists  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/5/a52484be49fe9e0c76b4fbc13ffd82bd3fa2112f.png)

Now I want to drop down list according to another column data  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ffe1ea65b4acd431c3d3751137ee249fe21cc452.png)

```auto
	if colName=='DefectType':
		root = self
		if root.data.getValueAt(row, 'Cmode')== 'R':
			#while the ColName=Cmode and value =R, use the query 
			query="select Code,Name from RubberDefect"
			DefectType=system.db.runQuery(query,'MaluProduction')
			return {'options':[(row[0], row[1]) for row in DefectType]}
		else:
			query2="select Code,Name from RubberDefectB"
			#while the ColName=Cmode and value <>R, use the query2
			DefectType=system.db.runQuery(query2,'MaluProduction')
			return {'options':[(row[0], row[1]) for row in DefectType]}

```

I have tried code, but not success, can you help to modify the code?

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [May 25, 2021, 6:07am UTC](https://forum.inductiveautomation.com/t/powertable-dropdown-dynamic/47072/2 "2021-05-25T06:07:24Z")

</div>

```auto
	if colName=='DefectType':
		root = self
		from javax.swing import JComboBox, DefaultCellEditor, DefaultComboBoxModel
		class CustomCellEditor(DefaultCellEditor):
			def getTableCellEditorComponent(self, table, value, isSelected, row, column):
				comp = DefaultCellEditor.getTableCellEditorComponent(self, table, value, isSelected, row, column)
				data = []
				if root.data.getValueAt(row, 'Cmode')== 'R':
					#while the ColName=Cmode and value =R, use the query 
					query="select Code,Name from RubberDefect"
					DefectType=system.db.runQuery(query,'MaluProduction')
					data=[(row[0], row[1]) for row in DefectType]
				else:
					query2="select Code,Name from RubberDefectB"
					#while the ColName=Cmode and value <>R, use the query2
					DefectType=system.db.runQuery(query2,'MaluProduction')
					data=[(row[0], row[1]) for row in DefectType]
				comp.setModel(DefaultComboBoxModel(data))
				return comp
		return {'editor': CustomCellEditor(JComboBox())}

```

I have try another code ,also not work

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7a452d713b172e99d856bdf930dde5658701a3ea.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 25, 2021, 12:33pm UTC](https://forum.inductiveautomation.com/t/powertable-dropdown-dynamic/47072/3 "2021-05-25T12:33:38Z")

</div>

I think you need to deliver an editor for editing and a renderer for display. The renderer can be the same component you use for editing, though.

Performance note: you are running queries inside these methods. _ **Don’t do that.** _ Create custom properties on the component and use some flavor of query binding to load those datasets. Reference the appropriate custom property in the extension method. That keeps the gateway round trip out of your component’s fast path.

Also consider defining your custom editor class in a project script and only _instantiating_ it in your extension method. (You will need an ` __init__ ` method as you won’t be able to rely on closures, but the end result should be faster.)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 30, 2026, 3:33pm UTC](https://forum.inductiveautomation.com/t/powertable-dropdown-dynamic/47072/4 "2026-01-30T15:33:48Z")

</div>

Reviving this thread for as I am doing this too for the first time in a while and am not sure what I am doing wrong here. I have a table and it has a custom property of a dataset, two columns, with the choices I care to display. Here are all my extension scripts in my scripting library.

```python
from javax.swing import JComboBox, DefaultCellEditor, DefaultComboBoxModel

EDITABLE_COLUMNS = ['LIN', 'LOX', 'PLAR','CLAR', 'weightSource']

class CustomCellEditor(DefaultCellEditor):
	def __init__ (self, choices):
		DefaultCellEditor. __init__ (self, JComboBox())
		self.choices = choices

	def getTableCellEditorComponent(self, table, value, isSelected, row, column):

		comp = DefaultCellEditor.getTableCellEditorComponent(self, table, value, isSelected, row, column)
		data = []
		for (idx, name) in system.dataset.toPyDataSet(self.choices):
			data.append(name)
		comp.setModel(DefaultComboBoxModel(data))
		return comp

def isCellEditable(self, rowIndex, colIndex, colName, value):
	"""
	Only the product and weight source columns are editable, any row.
	"""
	return colName in EDITABLE_COLUMNS and self.parent.editable

def onCellEdited(self, rowIndex, colIndex, colName, oldValue, newValue):
	self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)

def configureEditor(self, colIndex, colName):
	"""
	This is where we create our dropdown selection for weightSources.
	"""
	if colName == 'weightSource':
		return {'editor': CustomCellEditor(self.weightSources)}

```

However double clicking on my weight sources column just lets me edit the text instead of showing me the dropdown.

I have this working on another project though there I do it all in the extension function directly with the class / instantiation (eww I know) but now I am trying to do it this way and 1) its not working and 2) it seems like I am still instantation on each call anyways here.

What am I doing wrong? In the actual configureEditor extension function I am doing a `return PlantSetup.configureEditor(self, colIndex, colName)`
