# Vision Table Scrollbar Event

**URL:** <https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [January 9, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380 "2023-01-09T17:20:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [January 9, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380/1 "2023-01-09T17:20:13Z")

</div>

Is there a way to put a script on the scrollbar event of a table in vision? I would like to put a script on the table that would load more rows to the dataset when the user scrolls to about 75% of the way down.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 9, 2023, 6:07pm UTC](https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380/2 "2023-01-09T18:07:34Z")

</div>

For a granular hook, you would need to go from the component to its vertical scrollbar (literally `getVerticalScrollBar()`, then add an `AdjustmentListener` to it:  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JScrollBar.html#addAdjustmentListener(java.awt.event.AdjustmentListener)](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JScrollBar.html#addAdjustmentListener(java.awt.event.AdjustmentListener))

You'll want to do this only once, so in the `initialize` extension function of the table.

---

<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:** [January 10, 2023, 2:24am UTC](https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380/3 "2023-01-10T02:24:06Z")

</div>

> [@paul-griffith](#):
>
> `initialize` extension function of the table.

Note that a basic table doesn't have an initialize extension function, so to launch the script from there, a power table would need to be used instead. Of course, a listener could still be applied to a table, but it would probably need to be deployed from the parent window's internalFrameOpened event handler.  
Here is a sample script that is written for a basic table, but it would work for a power table as well. The script finds the scrollbar from within the table, and adds the necessary listener. Afterwards, anytime a user scrolls more than 75% of the way through the table, the listener will add 10 blank rows to the table:

```auto
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table')#For use from the internalFrameOpened event handler
from java.awt.event import AdjustmentListener
class scrollbarListener(AdjustmentListener):
	def adjustmentValueChanged(self, event):
		scrollPercentage = float(event.getValue())/float(event.source.getMaximum())
		if scrollPercentage > .75:#Adjust when to add rows here
			addRows()
def addRows():
	newRow = []
	for column in range(table.data.columnCount):
		newRow.append(None)
	for row in range(10):#Adjust the number of rows to add here
		table.data = system.dataset.addRow(table.data, table.data.rowCount, newRow)
scrollbar = table.getVerticalScrollBar()#getVerticalScrollbar()
adjustmentListener = scrollbarListener()
scrollbar.addAdjustmentListener(adjustmentListener)

```

**Edit:** replaced getScrollBar function with getVerticalScrollBar() method per Paul's suggestion which worked after correcting a capitalization error.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [January 11, 2023, 11:40pm UTC](https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380/4 "2023-01-11T23:40:36Z")

</div>

Thanks for all the help. This seems to work for me on a power table initialize extension method

```auto
	from java.awt.event import AdjustmentListener
	class ScrollbarListener(AdjustmentListener):
		def adjustmentValueChanged(self, event):
			extent = event.source.getModel().getExtent()
			scrollBarPosition = event.source.getValue()+extent
			scrollBarPositionMax = event.source.getMaximum()
			scrollPerc = 0 if scrollBarPositionMax == 0 else scrollBarPosition/float(scrollBarPositionMax)
			
			if(scrollBarPosition != scrollBarPositionMax):
				inifinityScroll(scrollPerc)
	
	def inifinityScroll(scrollPerc):
		loadThresholdPerc = self.loadThresholdPerc/100.0
		if(scrollPerc >= loadThresholdPerc):
			newRow = []
			for columnNum in range(self.data.columnCount):
				newRow.append("data")
			for rowNum in range(10):#Adjust the number of rows to add here
				data = system.dataset.addRow(self.data, newRow)
			self.data = data
	
	vertScrollBar = self.getVerticalScrollBar()
	adjustmentListener = ScrollbarListener()
	vertScrollBar.addAdjustmentListener(adjustmentListener)

```

---

<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:** [January 12, 2023, 5:38am UTC](https://forum.inductiveautomation.com/t/vision-table-scrollbar-event/68380/5 "2023-01-12T05:38:38Z")

</div>

Nicely done. I see that you're using a custom float property 'loadThresholdPerc' to make the _add_ point scriptable which makes sense, but the `newRow.append("data")` surprises me. Of course, if all of the columns are string columns this will never cause an issue.
