# Select the first row of a table as soon as it is done loading

**URL:** <https://forum.inductiveautomation.com/t/select-the-first-row-of-a-table-as-soon-as-it-is-done-loading/92699>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 2, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/select-the-first-row-of-a-table-as-soon-as-it-is-done-loading/92699 "2024-07-02T16:46:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 2, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/select-the-first-row-of-a-table-as-soon-as-it-is-done-loading/92699/1 "2024-07-02T16:46:26Z")

</div>

How would you go about this? I have implemented something that works much of the time, but is hacky and reliant on use of a Timer to continue checking whether the selection data exists. It seems like the only way this could work reliably would be to invoke the selection "on load" which is an event handler that Perspective doesn't have, and which I created [a request for](https://inductiveautomation.canny.io/ignition-features-and-ideas/p/perspective-view-onload-event-that-fires-when-the-view-is-done-loading) because of a different but similar scenario (the need to focus an input once a view is done loading).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 2, 2024, 4:49pm UTC](https://forum.inductiveautomation.com/t/select-the-first-row-of-a-table-as-soon-as-it-is-done-loading/92699/2 "2024-07-02T16:49:02Z")

</div>

Use a change event attached to the tables `props.data`. In the script, check if the length of the new data (handed to you in the event) is greater than zero. If so, set the selected row to zero.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 2, 2024, 5:02pm UTC](https://forum.inductiveautomation.com/t/select-the-first-row-of-a-table-as-soon-as-it-is-done-loading/92699/3 "2024-07-02T17:02:50Z")

</div>

I've tried that and it doesn't work:

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if len(currentValue.value) > 0:
		self.props.selection.selectedRow = 0

```

(It actually did work the very first time I opened the popup containing the view, but hasn't worked in any subsequent openings.)

This does work:

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	from threading import Timer
	
	def onLoad(self):
		self.props.selection.selectedRow = 0
	
	if len(currentValue.value) > 0:
		Timer(0.2, onLoad, [self]).start()

```

...but not on slower machines, or if I throttle my CPU.
