Deleting Multi-Selected Rows from Table
A common user experience is to select multiple rows of a table and then delete those rows from the database by clicking a Delete button. When the user selects more than one row in a table, there is a special function available on the table that makes accessible the row indexes of the table as a Python list. This list can be iterated through in order to delete the selected rows from the database as shown in this example code that can be called from a button's actionPerformed event handler.
data = event.source.parent.getComponent(
'Table'
).data #Get the data from the table and assign it to the variable called data.
rows = event.source.parent.getComponent(
'Table'
).getSelectedRows() #Get the rows of the data that the user has currently highlighted.
for
row in rows: #Iterate through each row of the list that is associated with the rows variable.
id = data.getValueAt(row,
"id"
) #Get the value associated with the current row and the the column called
"id"
system.db.runPrepUpdate(
"DELETE FROM tableName WHERE id = ?"
, [id]) #Run the query to delete from the database.
This code makes a few assumptions. First that there is table named tableName in your database, and that the table's Data property is bound to the same table.
Next...