Is there an easy way to get the entire row of data from a table into a custom property? I feel like I’m missing something!
First, I tried binding a dataset type property as:
{Root Container.Power Table.data}[{Root Container.Power Table.selectedRow}]
Secondly:
I tried making a script to do this for me but I get the error:
TypeError: toPyDataSet(): 1st arg can’t be coerced to com.inductiveautomation.ignition.common.Dataset
data = project.getData.getData()
headers = data.getColumnNames()
a = []
row = 30
for col in range(len(headers)):
colName = data.getColumnName(col)
a.append([data.getValueAt(row, colName)])
#ds = system.dataset.toDataSet(headers, a)
ds = system.dataset.toPyDataSet(a)
Ugg, I really am missing something. Just want to be able to pass selected data from a table without creating a new SQL table…
I don’t really like the idea of get every value and the create a new dataset. I’d prefer to eliminate every other rows so I can obtain a new dataset with only the selected row
Here it is the script:
table = event.source.parent.getComponent('Power Table')
selRow = table.selectedRow
PyTable = system.dataset.toPyDataSet(table.data)
IndicesToDelete = []
for x in range(0,len(PyTable)):
if x != selRow:
IndicesToDelete.append(x)
oneRow = system.dataset.deleteRows(PyTable,IndicesToDelete)
In oneRow you’ll have your new Dataset with only the selected row
PS: The next time, put your code in “Preformatted Text (Ctrl + Shift + C )” so it can be more readable like the one I posted
Although I’m not a big fan of these dataset methods. They lack the mutability and OO methods you expect in Python, which makes all Python code for it more awkward.
Great, thanks for the tips. System.dataset.deleteRows worked like a champ, I guess I won’t try to figure out why the list->dataset conversion wasn’t working before.
def getRowData(data, selRow):
IndicesToDelete = [i for i in range(len(data)) if i != selRow]
data = system.dataset.deleteRows(data, IndicesToDelete)
data = system.dataset.toPyDataSet(data)
return data
I bound the new dataset to a custom property via the onMousePress event handler because I couldn’t figure out how to pass dataset into a runScript command and bind it using the expression language:
data = self.data
self.rowData = project.getData.getRowData(data,rowIndex)