Using values in selected Row

Hello, (Skip to next paragraph for shorter entry)
I was doing some stuff with this program Ignition designer, when I came across a problem. I had put a table into a window, and set it up so that the user could select a row; but as I went on to continue, I noticed that I didn’t have a way to retrieve any of the data in the row the user selected, I have spent a good while trying to find out how to return or otherwise obtain any values contained inside of the row the user selected (such as the Primary Key). Hopefully I was wrong and you guys can point me into the right direction as to how to get values out of a Windows selected row within a Table.

Short Form: How do I get a value/ cell data out of the selected row within the Table Component.

P.S. I don’t normally post on forums, so I’m new to this. I tried to use common knowledge to determine the best way to go about it. If I messed anything up to where you feel the need to inform me, please do so.

table = event.source.parent.getComponent(“Table”)
selRow = table.getSelectedRow()
selCol = table.getSelectedColumn()

data = data.getValueAt(selRow, selCol)

You can build an event script for that table component using the mouse/mouseClicked event to do whetever you want with the row the user selected. I normally only do something if they double-click the row as it is too easy for someone to just single-click a row. Here is the script I use.

if event.button == event.BUTTON1: if event.clickCount > 1: GridData = event.source.data SRow = event.source.selectedRow PDataSet = system.dataset.toPyDataSet(GridData) value0 = PDataSet[SRow] [0] value1 = PDataSet[SRow] [1] value2 = PDataSet[SRow] [2] system.nav.openWindow("Popups/Details", {"Property0":value0, "Property1":value1, "Property2":value2})

In this example, I am only wanting the values of the first three columns in the row which the user double-clicked in the table.

The first line checks that we are only looking at button 1 on the mouse, or the left button for a right-handed user.

The second line checks that more than one click of the button happened.

The third line creates a dataset variable name GridData and copies the dataset of the table into it.

The fourth line creates a variable named SRow and sets it to the row number of the row the user double-clicked.

The fifth line creates a PyDataset variable named PDataSet, converts the dataset in GridData to a PyDataset, and assigns it to PDataSet.

The sixth, seventh and eighth lines create three variables named value0, value1, and value2 and assigns the value of column zero in the selected row of the PyDataSet to value0, the value of column one to value1, and the value of column two to value2.

The ninth line, in this example, opens a popup window named Details in the Popups folder, that has three previously assigned custom properties named Property0, Property1, and Property2, and passes the value of value0 to Property0, value1 to Property1, and value2 to Property2.

These three values can be used in the popup window to display the contents of the first three columns of the selected row in the table. If all you need is the primary key from the selected row, you would only need a value0 and a Property0. If you added a dataset property to the custom properties of the popup window, then you could use Property0 in a SQL query bound to that dataset to pull in the entire record of data for the selected row with a query such as…

SELECT * FROM MyTable WHERE PKey = {Root Container.Property0}

where PKey is the name of the primary key field in a table named MyTable. Now you have the entire record of data in that dataset in your popup window and can do with it as you please.

If any of this is not clear, let me know and I’ll explain further. My technical writing skills are not the best in the world.

1 Like

I usually just add a custom property onto the table for each column that I want

where Status is the name of the column.

1 Like

Thank you for the speedy responses. Looking at the solutions I can see it would have taken me a while to find them, thank you for saving much of my time.
Markdobtech, I tried yours first, and it would seem that the Table component does not have a .getValueAt method. Thanks for trying though.
RRRancher, I tried your solution and I worked beautifully, thank you.

There was an error in entering my response. The getValueAt function references the data property of table.

data = data.getValueAt(selRow, selCol)

Should be:

table.data = data.getValueAt(selRow, selCol)