# Datasets and Column/Field Indexes

**URL:** <https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 3, 2023, 10:55pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992 "2023-04-03T22:55:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [April 3, 2023, 10:55pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/1 "2023-04-03T22:55:10Z")

</div>

Hello all,

Is it possible to use a `table.props.selection.data[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/Table.props.selection.data[0]}, "none")`  
But I would like to add an index number like: `try({..../BottomContainer/TableContainer/Table.props.selection.data[0][1]}, "none")` to return the value of that column on the selected row.

Hope that makes sense.

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![kyler.kamyszek](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kyler.kamyszek](https://forum.inductiveautomation.com/u/kyler.kamyszek)\
**Post date:** [April 4, 2023, 12:44pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/2 "2023-04-04T12:44:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 2, 2023, 5:30pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/3 "2023-05-02T17:30:39Z")

</div>

I'm attempting to do it this way:  
`deptID = self.parent.parent.getChild("TableContainer").getChild("Table").props.selection.data[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").props.selection.data[0].DeptId` (This should work, as I just tested it in a new view, without other scripting)

Neither does this:  
`("Table").props.selection.selectedRow.value`

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 2, 2023, 6:16pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/4 "2023-05-02T18:16:01Z")

</div>

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

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

```

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

```python
return value.getValueAt(x, y)

```

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 2, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/5 "2023-05-02T18:54:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 2, 2023, 7:00pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/6 "2023-05-02T19:00:08Z")

</div>

Can we see what all this looks like ?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 2, 2023, 10:58pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/7 "2023-05-02T22:58:56Z")

</div>

Custom.dataset:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/d/ed9faa349a8939c84ebd22acec792765f83d720c.png)

Table:

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

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 2, 2023, 11:04pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/8 "2023-05-02T23:04:24Z")

</div>

> [@mdemaris](#):
>
> This does not work either.  
> `("Table").props.selection.data[0].DeptId` (This should work, as I just tested it in a new view, without other scripting)

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 3, 2023, 6:31am UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/9 "2023-05-03T06:31:18Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 5, 2023, 9:02pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/10 "2023-05-05T21:02:30Z")

</div>

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

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

Result:  
Success

Edit:

> [@pascal.fragnoud](#):
>
> You need to put in real values, of indices that match with a cell in the dataset

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`?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 5, 2023, 9:18pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/11 "2023-05-05T21:18:40Z")

</div>

> [@mdemaris](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [May 5, 2023, 9:25pm UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/12 "2023-05-05T21:25:20Z")

</div>

> [@pturmel](#):
>
> They don't magically get runtime values.

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 6, 2023, 7:22am UTC](https://forum.inductiveautomation.com/t/datasets-and-column-field-indexes/71992/13 "2023-05-06T07:22:01Z")

</div>

> [@mdemaris](#):
>
> This, then, would be hard coded to index `x` and index `y`, yes? For example, `x=1 y=2`.

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`.
