# Move scroll in table to location of selected row

**URL:** <https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238>\
**Category:** Ignition\
**Created:** [January 30, 2019, 10:08pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238 "2019-01-30T22:08:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [January 30, 2019, 10:08pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/1 "2019-01-30T22:08:22Z")

</div>

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

---

<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 30, 2019, 10:15pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/2 "2019-01-30T22:15:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [January 30, 2019, 10:18pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/3 "2019-01-30T22:18:34Z")

</div>

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

---

<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 30, 2019, 10:19pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/4 "2019-01-30T22:19:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [January 30, 2019, 10:22pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/5 "2019-01-30T22:22:54Z")

</div>

> [@paul-griffith](#):
>
> `scrollRowToVisible` :  
> `target.getTable().scrollRowToVisible(row)`

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

---

<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 30, 2019, 10:24pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/6 "2019-01-30T22:24:07Z")

</div>

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

```python
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

```

---

<div class="post-metadata">

**Author:** ![juang](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@juang](https://forum.inductiveautomation.com/u/juang)\
**Post date:** [January 30, 2019, 10:26pm UTC](https://forum.inductiveautomation.com/t/move-scroll-in-table-to-location-of-selected-row/22238/7 "2019-01-30T22:26:22Z")

</div>

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