Hello, I've got a tree component connected to a table. When I click an item on the tree, it queries data from sql with the selected id and the displayed table changes. I would like to delete the sql data that I select on the tree when I press DEL key.
I've read a post where it's encouraged to use Session Events. I've tried that approach but I can't manage to do it.
# Tree onItemClicked
def runAction(self, event):
self.parent.parent.getChild("SelectedFileTable").custom.uploaded_id = self.props.selectionData[0].value
In Perspective - Tree | Ignition User Manual the following information is given for selecitonData.
name |
Description |
Property type |
selectionData |
Array of objects containing the data and index path for all currently selected nodes. itemPath: Index path. Value is numeric. value: The value of the 'data' property for the selected node. |
Value is string. array |
We can see that you have,
items.1.items.0.data : 6
If you select that item on the tree then you should have two pieces of information in selectionData
.
selectionData.0.itemPath : 1/0
selectionData.0.value : 6
You are going to use SQL to delete the rows from the database so the data
property should contain a unique key for the query. For example, using a named query with four parameters it might look like this.
DELETE FROM ReportTable
WHERE idfile = :idfile
AND idcust = :idcust
AND idline = :idline
AND dateprod = :dateprod
That means that the data
field will look like this:
{
"idfile": 6,
"idcust": 991,
"idline": 1,
"dateprod": '2024-01-29'
}
Play with that. If you get into difficulty then please show how you are constructing the tree.
Thanks for the reply. I see that this would work, but how could I associate the delete query to a key press (DEL, for example)?
Add a key event listener in session events that broadcasts a message (system.perspective.sendMessage) and then listen for that event on your table.
2 Likes
Maybe check if the component is in focus first
2 Likes
Thanks for the advice (Sorry for the edits, I didn't see it was a response to PGriffith)