Perspective Table - Auto Select Row On Load

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!

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.

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.

1 Like

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

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.

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.

I'd say this is a bug.

2 Likes

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

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

And script for table startup event

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

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

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.

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.

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.

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.

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.

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

1 Like