Get value at selected row in perspective table

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?

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.

Thanks,
Priyanka Khandge

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

.getValueAt will only work for a dataset

Yes, resolved my problem using the below script:

	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')

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

1 Like

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

2 Likes

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

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.

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 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:

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]
2 Likes