Pulling Specific Cell Data from a Table

Hello, figured out almost everything I needed for my project but can't seem to figure this last bit out. I want to let the user select a row from a table that has 6 columns. From the row selected I want to send the order number over to the main page from the popup window. Here is what I have. I'm not sure what to add to the props.selection.data to just send the order number across. Any ideas anyone?

def runAction(self, event):
	textValue=self.getSibling("Table").props.selection.data
	payload = {
		"fieldFromPopup": textValue
	}
	
	system.perspective.sendMessage("receiveFromPopup", payload)
	
	system.perspective.closePopup("PopupForm")

props.selection.selectedRow will give you the selected row number.

EDIT: I think I misunderstood your question, whoops.

EDIT 2: On testing, @Transistor's syntax doesn't quite work if your data is formatted like the example table with the data array; it should be textValue = self.getSibling("Table").props.selection.data[0].city

textValue = self.getSibling("Table").props.selection.data.0.city
should give you the cell value (or whatever).

1 Like

My table is filled with data from my test SQL database.its showing as a dataset and doesn't have the various arrays like the example table has.

If it's a dataset, you should be able to use data.getValueAt(0, columnName)

EDIT: I tested it out and it looks like selection.data should still be an array of objects, even if the table source is a dataset. in that case Transistor's solution would apply (with the corrected syntax in my first post).

1 Like

sorry im not following entirely.

so it would be a combination of the two?

textValue = self.getSibling("Table").props.selection.data(0,columnName)

No, self.getSibling("Table").props.selection.data[0].columnName would be correct - I just tested it for myself. Sorry for the confusion.

I was under the impression that the selected data would also go through as a dataset, but that isn't the case.

This is what i'm putting in but its getting hung up

Can you open up the table props.selection.data for us? I'm guessing it's using a different name for that column internally.

You haven't really got a column named 'Order#' have you? Python will take the # as the start of a comment (as indicated by the editor changing color to green).

1 Like

yeah i think it is XD let me try and change the name

You shouldn't need to change the name, Perspective's almost certainly sanitized it somehow internally. You just need to find what the sanitized version is so you can use it in your code.

EDIT: looking at later screenshots, it looks like Perspective sanitizes nothing and happily keeps the # at the end of the column name, that's interesting and good to know.

I mean if that's your actual SQL column name maybe that's not the best name but that's neither here nor there :grin:

There's another way to reference the column name but I can't remember the exact syntax. Something like,
self.getSibling("Table").props.selection.data[0]['Order#']
Anyone?

2 Likes

Exactly what you have. Fixing the column names in the underlying data is preferred though.

2 Likes


Okay I changed the name of the column in my SQL database so the column name wouldn't have the # in it. Its still getting hung up though.

Could you go ahead and select a row in your table and then show us what that data structure looks like here?

That said, self.getSibling("Table").props.selection.data[0]['OrderNumber'] should work at this point, as mentioned above.

image


here you go

1 Like

I see you're pulling from props.data instead of props.selection.data. That would do it

you got it, thanks so much!!!!