# Excel-like cell behavior in a table

**URL:** <https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [September 13, 2023, 3:39pm UTC](https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090 "2023-09-13T15:39:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [September 13, 2023, 3:39pm UTC](https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090/1 "2023-09-13T15:39:59Z")

</div>

Hello,

I'm using Ignition version 8.1.26 and I'd like to have Excel-like cell behavior in my table for Tab and Enter keypresses. I thought I could script this with an onKeyPress event but I'm not having any luck.

Here is what I have. I'm really new to python so I'm sure my code is really bad.

```auto
def runAction(self, event):
	# Get the currently selected cell coordinates
	#I don't think this part is working.
	selectedRow = self.getSibling('Table1').props.selection.selectedRow
	print(selectedRow)
	selectedColumn = self.getSibling('Table1').props.selection.selectedColumn
	print(selectedColumn)
	
	if event.keyChar == '\t': # Tab key
	    # Calculate the next column index
	    nextColumn = selectedColumn + 1
	    
	    # Check if we've reached the end of the row
	    if nextColumn >= event.source.data.columnCount:
	        # Move to the first cell of the next row
	        nextRow = selectedRow + 1
	        if nextRow >= event.source.data.rowCount:
	            nextRow = 0 # Cycle back to the first row
	        event.source.selectedRow = nextRow
	        event.source.selectedColumn = 0
	    else:
	        event.source.selectedRow = selectedRow
	        event.source.selectedColumn = nextColumn
	
	elif event.keyChar == '\n': # Enter key
	    # Calculate the next row index
	    nextRow = selectedRow + 1
	    
	    # Check if we've reached the end of the table
	    if nextRow >= event.source.data.rowCount:
	        nextRow = 0 # Cycle back to the first row
	    
	    event.source.selectedRow = nextRow
	    event.source.selectedColumn = selectedColumn

```

Thank you,

---

<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:** [September 13, 2023, 5:42pm UTC](https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090/2 "2023-09-13T17:42:29Z")

</div>

Are you getting any errors when this runs? What extension function do you have this in? I think you want `system.perspective.print` to see those values come through. Did you test to see what the `event.keyChar` is when you press enter or tab? You can always start littering this thing with print statements to see how far your script is getting and what branch it is going down.

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [September 13, 2023, 5:53pm UTC](https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090/3 "2023-09-13T17:53:52Z")

</div>

I currently have this in the onKeyPress event. I don't know what you mean by extension function.

I changed the print to system.perspective.print() and am now getting an error:

> File "function:runAction", line 8, in runAction  
> AttributeError: 'com.inductiveautomation.ignition.common.script.ada' object has no attribute 'keyChar'

Still nothing printing in the console though. Thanks!

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 13, 2023, 5:57pm UTC](https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090/4 "2023-09-13T17:57:30Z")

</div>

So you were using

```auto
print()

```

Which in perspective will send that to the wrapper log for the gateway.

Like @bkarabinchak.psi mentioned use

```auto
system.perspective.print()

```

That will do to the proper console so you can see it.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 1, 2023, 5:08am UTC](https://forum.inductiveautomation.com/t/excel-like-cell-behavior-in-a-table/79090/5 "2023-10-01T05:08:22Z")

</div>

I was able to see the `onKeyDown` event respond to the keys in the diagnostic console using the following script:

```auto
	keyCode = event.key
	if keyCode == "Tab":
		system.perspective.print(keyCode)
	elif keyCode == "Enter":
		system.perspective.print(keyCode)

```

This works consistantly for the enter key, but unfortunately, when the tab key was pressed, the table lost focus, and I was unable to register any subsequent events.
