# Get value at selected row in perspective table

**URL:** <https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 15, 2024, 7:09am UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384 "2024-03-15T07:09:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [March 15, 2024, 7:09am UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384/1 "2024-03-15T07:09:49Z")

</div>

Hi guys,

I'm trying to get the selected row value but facing the below problem.

Does anyone have any idea what is wrong on my end?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2fbb39ffb355711a9498d259d17090958d7cb488.png)

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value != '' and currentValue.value != -1:
		self.view.params.value = self.props.data.getValueAt(currentValue.value, self.props.selection.selectedColumn)

```

This script was added in selectedRow onchange script.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/4/b4d3bcfc1a2198be5653105b19a32cba91e89ff6.png)

Thanks,  
Priyanka Khandge

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [March 15, 2024, 8:55am UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384/2 "2024-03-15T08:55:09Z")

</div>

How is the data being returned, as a JSON or dataset?

`.getValueAt` will only work for a dataset

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [March 15, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384/3 "2024-03-15T09:18:12Z")

</div>

Yes, resolved my problem using the below script:

```auto
	if currentValue.value != '' and currentValue.value != -1:
		headers = []
		data = []
		arrayDataset = self.props.data
		for row in arrayDataset:
			if not headers:
				headers = row.keys()
			data.append([val for key,val in row.iteritems()])
			
		dataset = system.dataset.toDataSet(headers,data)
		self.view.params.value = dataset.getValueAt(currentValue.value, self.props.selection.selectedColumn)
		self.view.params.ID = dataset.getValueAt(currentValue.value, 'ID')

```

---

<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:** [March 15, 2024, 9:20am UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384/4 "2024-03-15T09:20:47Z")

</div>

Tip: "value" probably isn't a great name for a view parameter!  
Change it before you've used it in too many places.

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [March 15, 2024, 9:32am UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384/5 "2024-03-15T09:32:27Z")

</div>

Probably worth noting that if possible, probably want your data in props to be a dataset. For large amounts of data they do run more efficeintly than a JSON

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 15, 2024, 3:12pm UTC](https://forum.inductiveautomation.com/t/get-value-at-selected-row-in-perspective-table/87384/6 "2024-03-15T15:12:18Z")

</div>

Or at the very least, avoid converting the data from a list to a dataset just to pull a value out of it!

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value != '' and currentValue.value != -1:
		self.view.params.value = self.props.data["ID"]

```

Edit: I focused so much on the ID piece I didn't see that you were trying to get a dynamic value based on the selectedColumn value.

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value != '' and currentValue.value != -1:
		self.view.params.value = self.props.data[currentValue.value][self.props.selection.selectedColumn]

```

What version are you using? Tables provide [access to this information](https://www.docs.inductiveautomation.com/docs/8.1/appendix/components/perspective-components/perspective-display-palette/perspective-table#:~:text=An%20array%20of%20objects%20representing%20the%20current%20selection.) in a property already. It _might_ be hidden behind that tooltip.

I think a better solution here is to bind some custom prop with an expression structure binding, and only perform the write to your param within the change script:

 ![Screenshot 2024-03-15 at 8.25.37 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fd3594fd4512954b4140bcdb1bbd0fc753d0742a.png)

```auto
def transform(self, value, quality, timestamp):
	# An assumption here: Only one row may be selected at a time
	# We actually don't care about the selectedRow part of the value, we just want this binding to
	# re-evaluate whenever that value changes, OR when the data changes, OR when the selectedColumn
	# changes. After placing this binding, your change script on Table.props.selection.selectedRow
	# should ONLY write this custom prop value to the param prop you've set up.
	return value.data[0][value.selectedColumn]

```
