# Perspective Table - Auto Select Row On Load

**URL:** <https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 13, 2024, 9:01pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335 "2024-05-13T21:01:41Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 13, 2024, 9:01pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/1 "2024-05-13T21:01:41Z")

</div>

I have a simple view with a table component on it, and when the view is opened, I want to automatically select one of the rows in the table.

Currently, I am simply passing in the selected row I want as a parameter to the view, and have a script on the on change event of the table props.data property which sets that value on the selection.selectedRow property. The problem is that the row doesn't visually show as selected if my dataset hasn't rendered in the table yet (in the case that I have a large dataset to load). So I'm running into a race condition where I need to programmatically wait for my dataset to render before I can execute my row selection script.

I'm trying to figure out if I can either trigger an event when Ignition has finished rendering the table (and then select the row from there), or if there's another way to select the row before the table renders and have it be able to visually display the row as selected on load.

Any suggestions would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 13, 2024, 9:22pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/2 "2024-05-13T21:22:08Z")

</div>

> [@areid](#):
>
> ... have a script ... which sets that value on the selection.selectedRow property.

I think you'll find that the selectedRow property is read-only.

There's some related discussion on the difficulties of what your proposing in [[IGN-7140] Perspective Table - add `props.selection.selectedRows` - #7 by cmallonee](https://forum.inductiveautomation.com/t/ign-7140-perspective-table-add-props-selection-selectedrows/69378/7).

---

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 13, 2024, 9:29pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/3 "2024-05-13T21:29:23Z")

</div>

I can definitely write to the selectedRow property and have it visually select the row that I want. We have done it on past projects successfully. The only difference is that in past projects, we'd be selecting records based on some other action that happens long after the table has rendered.

I can also see that if I throw a sleep command prior to running my row selection script, it does actually work. I'm just trying to find a more robust way of doing it so I can avoid intentional sleeps.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 13, 2024, 9:31pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/4 "2024-05-13T21:31:05Z")

</div>

Ah, OK. I'm misremembering something I read on the forum. It may be the `selection.data` I was thinking of.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 13, 2024, 9:32pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/5 "2024-05-13T21:32:21Z")

</div>

Did you try with a binding ?  
You might very well have the same problem, but it's worth a shot.  
Also, you should probably use bindings anywhere you can instead of scripts anyway.

---

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 14, 2024, 1:04pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/6 "2024-05-14T13:04:19Z")

</div>

Good suggestion, but unfortunately I didn't have any luck.

Because a binding resolves immediately, the selectedRow value is set even faster that way. When that's the case, even a smaller dataset doesn't have time to render on the screen before the selectedRow is set, so I get the same issue.

---

<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:** [May 14, 2024, 1:09pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/7 "2024-05-14T13:09:10Z")

</div>

I'd say this is a bug.

---

<div class="post-metadata">

**Author:** ![Ujwal\_Wankhede](https://avatars.discourse-cdn.com/v4/letter/u/4af34b/32.png) [@Ujwal\_Wankhede](https://forum.inductiveautomation.com/u/Ujwal_Wankhede)\
**Post date:** [May 14, 2024, 1:27pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/8 "2024-05-14T13:27:43Z")

</div>

I have added following change script on `props.selection.selectedRow`

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

```

And script for table startup event

```python
def runAction(self):
	self.props.selection.selectedRow = None

```

It's working.  
Is it something you are looking ?

---

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 14, 2024, 1:35pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/9 "2024-05-14T13:35:43Z")

</div>

I just tried that now, and it doesn't seem to work consistently, even with small datasets. Again it seems to be that if selectedRow is set before the table has rendered on the screen, it doesn't visually display.

---

<div class="post-metadata">

**Author:** ![Ujwal\_Wankhede](https://avatars.discourse-cdn.com/v4/letter/u/4af34b/32.png) [@Ujwal\_Wankhede](https://forum.inductiveautomation.com/u/Ujwal_Wankhede)\
**Post date:** [May 14, 2024, 1:53pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/10 "2024-05-14T13:53:47Z")

</div>

> it seems to be that if selectedRow is set before the table has rendered on the screen

Agree.  
But the workaround I suggested is behaving like below.

---

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 14, 2024, 2:09pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/11 "2024-05-14T14:09:59Z")

</div>

I understand what you're saying, but the workaround you're suggesting is inconsistently working with any dataset larger than what you have here.

For example, I was working with a 5x40 dataset size, and your suggestion was only working about a tenth of the time in my designer.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 14, 2024, 2:33pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/12 "2024-05-14T14:33:37Z")

</div>

I suspect it only _works_ when the script execution is long enough to delay the assignment to the property. It's basically a dice-throw sleep.

Is the dataset data dynamic ? I mean, will it change once the page is loaded ?  
If not, maybe you can try adding a custom prop that's bound to that dataset. This prop will reevaluate when the dataset changes. Which means you should be able to then use that custom prop to check if the data was loaded or not, and then set the properties you want.  
Maybe. We're entering hacky workarounds territory.

---

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 14, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/13 "2024-05-14T14:48:42Z")

</div>

So what you're suggesting is actually the method that we've landed on for the time being. However, that doesn't fully solve the problem, because even if the dataset has the correct value, if the table hasn't actually rendered on the screen yet, then the selectedRow value won't select a row visually, which means we can't simply rely on the value change event of the data property. So in that case as well we've had to add in a manual sleep to wait for the table to render.

---

<div class="post-metadata">

**Author:** ![areid](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@areid](https://forum.inductiveautomation.com/u/areid)\
**Post date:** [May 22, 2024, 12:56pm UTC](https://forum.inductiveautomation.com/t/perspective-table-auto-select-row-on-load/90335/14 "2024-05-22T12:56:41Z")

</div>

Just following up on this. I reached out to Inductive Automation support, and they have logged it as a bug. IGN-9900
