# Default table view at bottom

**URL:** <https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418>\
**Category:** Ignition\
**Created:** [May 29, 2019, 10:07pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418 "2019-05-29T22:07:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [May 29, 2019, 10:07pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/1 "2019-05-29T22:07:10Z")

</div>

Hi,

I am looking for a way to have the default view of a Power Table be focused to the last row of a table. The table is pulling data from a SQL table and I currently have the default Selected Row to be:

```auto
SELECT COUNT(*) - 1
FROM tableName
WHERE colName = {selectedStringValue}

```

This seems to work fine but does not force the table view to show that row. Is there any formatting option for this?

I essentially want the table to scroll up with new entries instead of down.

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [May 30, 2019, 6:51pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/2 "2019-05-30T18:51:20Z")

</div>

I can get it to work from a button with the following script, but the window event handlers seem to be overriding this (I see the scroll jump down and then jump back up).

Is there a better event handler (vs InternalFrameActivated, InternalFrameOpened, or VisionWindowOpened) for this type of script that will just set the default view to the bottom?

```auto
from javax.swing import JTable

table = event.source.rootContainer.getComponent("Power Table")
myJTable = table.getTable()
targetRow = 9999999
rectangle = myJTable.getCellRect(targetRow,0,0) 
myJTable.scrollRectToVisible(rectangle)

```

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [May 30, 2019, 7:10pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/3 "2019-05-30T19:10:15Z")

</div>

Okay, it seems to work with the InternalFrameActivated event handler but only scrolls to the second to last row. When I have it triggered with a button event handler the Viewport goes all the way to the bottom as I want. What gives?

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [May 30, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/4 "2019-05-30T19:19:15Z")

</div>

I believe it has something to do with window size? It works when the window is made much smaller.

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [May 30, 2019, 8:09pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/5 "2019-05-30T20:09:17Z")

</div>

InvokeLater seems to help, but any future input would be appreciated.

```auto
def scrollTo():
	from javax.swing import JTable
	table = event.source.rootContainer.getComponent('Power Table')
	myJTable = table.getTable()
	targetRow = 100000001
	rectangle = myJTable.getCellRect(targetRow,0,0) 
	myJTable.scrollRectToVisible(rectangle)
system.util.invokeLater(scrollTo,100)

```

By the way we are trying to get this to run on Mobile via a windows browser.

---

<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:** [May 30, 2019, 8:14pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/6 "2019-05-30T20:14:14Z")

</div>

`invokeLater` probably is the “right” solution - there’s an inherent race between the data property updating, which will then fire the binding on `selectedRow`, which probably completes before the data binding has finished evaluating _and_ put all the rows into the actual table dataset. `invokeLater` gives the data property time to finish its workload before trying to scroll the table.

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [May 30, 2019, 9:59pm UTC](https://forum.inductiveautomation.com/t/default-table-view-at-bottom/25418/7 "2019-05-30T21:59:46Z")

</div>

Great, thank you very much!
