Move scroll in table to location of selected row

Hi, i have a code for Add row. as follows. on a power table.

table = event.source.parent.getComponent(‘Power Table 1’)
newrow= ("","","","","","","","","","","")
table.data = system.dataset.addRow(table.data, newrow)
table.selectedRow = len(system.dataset.toPyDataSet(table.data)) - 1
table.selectedColumn = 0

THIS IS WORKING PERFECTLY

But my table has more than a 1000 rows and keeps adding everyday. so whenever i add a row. i need the scroll to move to the selected row.

right now the scroll bar stay on the location that it is and the next row it id not visible so it make this complicated for my employees to use. any help? i read a topic on a jtable but did not know how to use the code. if anyone can help me with the code i will appreciated.

Juan

Assuming target is a reference to the Power Table component, just use scrollRowToVisible:
target.getTable().scrollRowToVisible(row)

1 Like

thanks but where i put this code. that was my question. as i don’t know

Put it directly below your existing logic, right after setting the selectedRow with table.selectedRow = len(system.dataset.toPyDataSet(table.data)) - 1

ok so i put it exactly like you told me and it does not work. it says it expects new line.

Sorry, my formatting was a little misleading. You only need the last line; so all together would be something like:

table = event.source.parent.getComponent(‘Power Table 1’)
newrow= ("","","","","","","","","","","")
table.data = system.dataset.addRow(table.data, newrow)
lastRow = len(system.dataset.toPyDataSet(table.data)) - 1
table.selectedRow = lastRow
table.getTable().scrollRowToVisible(lastRow)
table.selectedColumn = 0
3 Likes

thank you so much, and sorry for my lack of knowledge. it is greatly appreciated.