Ignition - Table Component: Scroll Bar Hide & Selected Row

Ok, so after a bit of messing around, I modified my original function to work with both template repeaters and both types of tables (as well as made my previous function more efficient, if you saw the previous version of this post).

Call with E.g.:

scrollableObj = event.source.parent.getComponent('Table')
scrollToPos(scrollableObj, "Col 1", 30) # scroll to (the first) cell value with 30 for column "Col 1"
def scrollToPos(scrollableObj, DataSetFieldName, NewDataSetPosValue, position=0):
	'''
	Description:
	Scrolls the table component to the item above the new position.
	
	Arguments:
	scrollableObj			- the scrollable component (table, power table, template repeater - untested with any others)
	DataSetFieldName		- the field name in the templateParams dataset to find the new position value in
	NewDataSetPosValue		- the field value of the field name to find in the dataset to move to
	Position				- the position to scroll to:
								0 - item at the top minus 1
								1 - item in the centre
	
	Revision:
	No.		Date		Author			Comment
	1.0		2018-11		Nick Minchin	Original
	1.1		2019-12		Nick Minchin	Simplified function. Can set value of scrollbar directly without having to use the viewport.
	1.2		2019-12-15	Nick Minchin	Simplified further method to get the scrollbar object. Added ability to change scroll to position type.
	'''
	objType = str(type(scrollableObj))
	
	#get the component's items dataset so that we can work out the current index of the maximum
	if any([t in objType for t in ['PMITable', 'VisionAdvancedTable']]):
		ds = scrollableObj.data
	if any([t in objType for t in ['TemplateRepeater']]):
		ds = scrollableObj.templateParams
	
	ds = system.dataset.toPyDataSet(ds)
	
	if len(ds) > 0:
		#find the index of the new item from the dataset
		index = 0
		for i in range(len(ds)):
			if ds[i][DataSetFieldName] == NewDataSetPosValue:
				index = i
		
		scrollBar = scrollableObj.verticalScrollBar
		tableHeight = scrollableObj.height
		itemHeight = scrollableObj.rowHeight
		itemsInView = tableHeight / itemHeight
		
		#Calculate the position of the current step using the item height and the new item's index
		if position == 0:
			newPos = int(itemHeight*(index-1))
		elif position == 1:
			newPos = int(itemHeight*(index - itemsInView/2))
		else:
			newPos = int(itemHeight*(index-1))
		
		scrollBar.setValue(newPos)