Power Table Cell Edit Dropdown menu with freeform entry with auto-fill

Curious if anyone has accomplished the below:

Being able to edit a cell in a power table by double clicking on the cell and you either select a value from the dropdown menu OR start typing and it tries to auto-fill or provide more specific options as you type.

Similar to how Excel works - it tries to guess what you want.

I've looked through the forum and didn't find anything close enough to give me a starting point. So far I have the dropdown menu working but that prevents freeform text entry. I'm hoping there is an elegant way to accomplish using java tools.

The other option (which I don't like and what I found in the forum) is to do a bunch of hidden components and passing around what is being typed into queries and then having to pass values back to the power table cell. So mimicking the drop down by a hidden table/list.

Any thoughts?

You can supply a column editor in the extension method. That editor can supply any arbitrary JComboBox you like, on demand.

Start here:

https://forum.inductiveautomation.com/search?q=TableCellEditor

Thanks! I just stumbled onto those threads. Looks like I have options.

Ok, I got this working with a few exceptions that I'm still trying to figure out. One of them is committing the selection or text when enter is pressed.

From some google searches it seems the key bindings for the JComboBox don't use the ENTER key to commit but rather uses it to show the dropdown, is that accurate? Also, saw some saying it wasn't a good idea to route that functionality. Thoughts?

Below is the code so far:

	from javax.swing import AbstractCellEditor,JComboBox, JTextField
	from javax.swing.table import TableCellEditor
	from java.awt.event import ItemListener, ItemEvent
	
	menus = self.menus
	menuList = []
	for item in system.dataset.toPyDataSet(menus):
		menuList.append(item[3])
		
	class MyItemListener(ItemListener):
				
		# Constructor
		def __init__(self, table, value, rowIndex, colIndex):
			self.table = table
			self.rowIndex = rowIndex
			self.colIndex = colIndex
			self.value = value
				
			self.menuList = menuList
			
		
		# this is fired when the combobox changes
		def itemStateChanged(self, event):
			if (event.getStateChange() == ItemEvent.SELECTED):
				newValue = event.getItem()
				# create a new dataset with the updated value					
				newDS = system.dataset.setValue(self.table.data, self.rowIndex, self.colIndex, newValue)
				
				# write back to the source property
				# update this to whereever your master data is
				self.data = newDS
	
	class myTableCellEditor(TableCellEditor, AbstractCellEditor):	
	
		def __init__(self, tableComponent):
			self.table = tableComponent
			self.editor = None
			self.menuList = None

		def getTableCellEditorComponent(self, table, value, isSelected, rowIndex, vColIndex):	
			
			self.menuList = menuList
			
			self.editor = JComboBox(self.menuList)
			self.editor.setEditable(True)
#			index = self.menuList.index(value)
#			self.editor.setSelectedIndex(index)
#			self.editor.addItemListener(MyItemListener(self.table, value, rowIndex, colIndex))

			return self.editor
		
		def getCellEditorValue(self):
			newValue = self.editor.getSelectedItem() 

			return newValue


	if colName == "comment":
		m = myTableCellEditor(self)
		return {"editor":m}

Not sure if I even need the addItemListener - which is why it's commented out.

Thanks for any help or direction!