Datasets and Column/Field Indexes

Hello all,

Is it possible to use a[column index] to return the value of the first (or second...) column of the selected row?

I am using one table, and changing it's source based on user actions. The column name changes, so hard-coding the name won't work.

I was using something like this: try({..../BottomContainer/TableContainer/[0]}, "none")
But I would like to add an index number like: try({..../BottomContainer/TableContainer/[0][1]}, "none") to return the value of that column on the selected row.

Hope that makes sense.


Unfortunately the object in the selection data doesn't sort relative to the data source when going through that data (for loop).

Could you store the column name in a custom property that you would want to return?

You could pull that column from the script/binding that generates the data source.

Or you could pull the row ID or unique identifier from the selection then get the column 1 or 2 data associated with that by referencing the data source.

I'm attempting to do it this way:
deptID = self.parent.parent.getChild("TableContainer").getChild("Table")[0]['DeptId']

I can change the name of the column, DeptId, to match whatever column name is going to appear in the table. But, I don't think the variable deptID is getting the value. So, I think I need some clarification as to what the [0]['Field Name?'] parameters really mean? I was assuming a key/value or row/column, but something isn't adding up.

When I run the view in "Preview Mode" in the designer, and click on a row, the selectedColumn and selectedRow show "DeptId" and 0, respectively. So that seems to match up, but why doesn't the variable get the selected Row value?

This does not work either.
("Table")[0].DeptId (This should work, as I just tested it in a new view, without other scripting)

Neither does this:

I'd set up a custom prop, bind it to, and add this transform:

def transform(self, value, quality, timestamp):
	return value[x].values()[y]

that's assuming is not a dataset.
If it is:

return value.getValueAt(x, y)

So, bound to query, Table.custom.dataset bound to with a script transform return value.getValueAt(x,y) returns a null on the custom.dataset. (And the table data has 14 records.)

Can we see what all this looks like ?



This does work, there was another line of code that prevented the whole script from running.

Well, what's the error ?

edit: Nevermind. I watched the screenshot better and I can guess the error.
You put in x and y as the indices. That's not gonna work, x and y don't exist.
You need to put in real values, of indices that match with a cell in the dataset.

Let's take a step back. What are you trying to achieve ?

to change the table's data source based on user action, aka clicking a button.

create a custom prop for each data source needed - bound to named query
use button event scripting to set the table's data source to the appropriate custom prop



This, then, would be hard coded to index x and index y, yes? For example, x=1 y=2.
That returns a row from the SQL table, basically, Field 1 and Field 2, as if from a SELECT statement?
For example from columns FirstName and LastName values John and Doe?
Or, is the x,y going to return the value found at column x and row y?

row number in variable x and column number or name in variable y, but only if x and y are defined somewhere. They don't magically get runtime values.

I was sure Ignition used some sort of mystical magic! Bubble busted, lol.

You could hard code them if the values are always the same and you know what those values are.
ie: you always want the first value of the 'foo' column: value.getValueAt(0, 'foo')
Or, they could be variables. x could be the result of some processing and y a value selected by a user through another component. It doesn't matter how they're defined, as long as they're defined (and don't result in an out of bounds error).
But in the transform screenshot you posted before, x and y where not defined, which resulted in the Error_ScriptEval.

1 Like