Hi,
I have a dataset tag.
The dataset data is filtered and shown in a table by a script in a button in perspective.
When the dataset get updated by a gateway script, the table flickered and cleared.
To avoid the table getting cleared, three custom properties were added:
FilterValue = Filter used to filter the data
RawData = holds the Dataset tag, updated via a tag binding
FilteredData = holds the filtered data, updated via the RawData onChange script
This solution fixed the table getting cleared.
But now, if the table has a row selected and the table gets updated, it clears the selected row even though the table looks like it is still selected. Even if you click on the same row again, it doesn’t get selected.
This code then, gives an error coming from getValueAt().
This wasn’t happening before the “get cleared solution” was introduced. This code was able to detect if a row was selected or not but it doesn’t detect that the selected row is cleared on the background:
def runAction(self, event):
#Logger:
strLogName = "MoveTrolleyPB"
log = system.util.getLogger(strLogName)
Blast_Contents_Table_SelectedRow = self.getSibling("Table").props.selection.selectedRow
if Blast_Contents_Table_SelectedRow is not None and Blast_Contents_Table_SelectedRow >= 0:
# --- Read tags
ReadTagList = [
"[Plant_Model]Blast_Contents/Blast_Contents_List",
"[System]Gateway/CurrentDateTime.value"
]
values = system.tag.readBlocking(ReadTagList)
Blast_Contents_DataSet = values[0]
CurrentDT = values[1].value
# Prepare data:
# Get a reference to the table component
table = self.getSibling("Table")
# Get the table data (list of dictionaries)
tableData = table.props.data
# Access a specific column value by its key
In_trolley = tableData.getValueAt(Blast_Contents_Table_SelectedRow, "Trolley")
Bl_Moving = True
ST_Probe = ''
ST_Blast = ''
DT_End_Position_DT = CurrentDT
# --- Write Data Set:
row = 0
for row in range(Blast_Contents_DataSet.value.getRowCount()):
if Blast_Contents_DataSet.value.getValueAt(row, 3) == In_trolley:
#Write tag
WriteTagList = [
"[Plant_Model]Blast_Contents/Blast_Contents_List[" + str(row) + ",4]",
"[Plant_Model]Blast_Contents/Blast_Contents_List[" + str(row) + ",5]"
]
WriteValues = [ST_Blast, ST_Probe]
system.tag.writeBlocking(WriteTagList, WriteValues)
break # Exit loop after finding match
#endif
#Next for
else:
#Show message:
id = 'MessageView'
view = 'Templates/Message'
params = {'Message01': 'Please select a row'}
title = 'Message'
system.perspective.closePopup(id)
system.perspective.openPopup(id, view, params, title, showCloseIcon = True)
#endif
I read this forum:
where pturmel gave this solution:
The trick is to set enableRowSelection to False, and have a change script on selectedRow looking for None, and then changing enableRowSelection back to True. The code must not set enableRowSelection to False when selectedRow is already None.
Basically, row selection can only be performed reliably by the client browser. When you disable row selection, that state gets sent to the browser, and it clears the selection. When you see that change back in the gateway, you can re-enable row selection.
I have tried to introduce it in my project by:
Phase 1 - Manually
Manually I toggle table property EnableRowSelection
The “selected” row at the table gets cleared
It works!
Phase 2 – Automate it
- A new custom property was added in the view: EnableRowSelection
- In the RawData onChange script, the custom property gets reset:
if EnableRowSelection:
self.custom.EnableRowSelection = False
#endif
- The table property EnableRowSelection gets updated via a property binding with the custom property EnableRowSelection
- An onChange script is added to the table property EnableRowSelection
if currentValue.value is False:
self.view.custom.EnableRowSelection = True
#endif
I can see how the table property EnableRowSelection gets set and reset but it doesn't work. The “selected” row is still selected even though it isn’t.
Do you know how could I detect that the selection is cleared in the background and how to reselect it?
Thanks in advance.