How can I select a row from a table and show the info of that row in a popup so i can process it on the db later on.
In Ignition Vision was done like:
root = system.gui.getParentWindow(event).getRootContainer()
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Page2.tblWorkRequest')
selected_row = table.selectedRow
if selected_row < 0:
system.gui.messageBox('<html>Please select a row to process', 'Comirt')
elif table.data.getValueAt(selected_row, 8) != 'Pending':
system.gui.messageBox('<html>The selected row is not pending processing', 'Comirt')
else:
if system.gui.confirm(
'<html><p>Please confirm the approval of the request:</p>' +
'<p><b>Number:</b> ' + str(int(table.data.getValueAt(selected_row, 0))) + '</p>' +
'<p><b>Building:</b> ' + table.data.getValueAt(selected_row, 1) + '</p>',
'Connet'
) == True:
project.PRL.CommonTask.DoGenerateWorkOrderFromWorkRequest(root.PrismaCompany, table.data.getValueAt(selected_row, 0))
Use the props.selection.data
property.
1 Like
Something like:
table = self.getSibling("tblWorkRequest")
selected_rows = table.props.selection.data
?
Please don't mark an answer as ✓ Solution if you don't know how it works!
1 Like
Thanks to the input I found a solution on how to pass row data to a popup window. I share here.
def runAction(self, event):
table = self.getSibling("tblWorkRequest")
selected_rows = table.props.selection.data
if not selected_rows:
system.perspective.messageBox("Please select a row to process", title="Notice")
else:
selected_row = selected_rows[0]
sede = selected_row.get("SEDE")
solicitud = selected_row.get("SOLICITUD")
popup_params = {
"sede": sede,
"solicitud": solicitud
}
system.perspective.openPopup(
id="aprobar-popup",
view="Page/Aprobar",
params=popup_params,
title="Aprobar Solicitud",
modal=False,
width=400,
height=300
)
Tips:
- If this script is in a button then put an expression binding on the button's enabled property:
if(
!isNull({../Table.props.selection.selectedRow}),
true,
false
)
Now you don't need if not selected_rows:
, etc. because the button won't work1.
- You can pass the whole row in one line. The script can be reduced to this (untested):
def runAction(self, event):
table = self.getSibling("tblWorkRequest")
system.perspective.openPopup(
id = "aprobar-popup",
view = "Page/Aprobar",
params = table.props.selection.data[0],
title = "Aprobar Solicitud",
modal = False,
width = 400,
height = 300
)
(My indents above are a mix of spaces and tabs. You need to fix.)
1 onActionPerformed checks the enabled property. It doesn't fire if the component is disabled.
onClick fires whether enabled or not (so don't use it).
1 Like
Thanks for the code, I will try, also thanks for the onActionPerformed advice.