Delete Selected Rows From Table In Perspective?

How is this accomplished? It is so easy to do in Vision. I can not seem to get this done in Perspective.

The Perspective Table is completely driven by the data it is provided in the props.data property. If you want rows removed, then you need to remove those rows from the data.

You should look into using Table.props.selection.data in conjunction with a separate button component. When the button is clicked it should perform something like this (tested locally):

	current_data = self.getSibling('Table').props.data
	rows_to_remove = self.getSibling('Table').props.selection.data
	known_colum_key = 'city'
	rows_to_keep = []
	unique_values_to_remove_on_match = [row[known_colum_key] for row in rows_to_remove]
	for row in current_data:
		if row[known_colum_key] not in unique_values_to_remove_on_match:
			rows_to_keep.append(row)
	self.getSibling('Table').props.data = rows_to_keep

You’ll obviously need to update this code depending on the name of your Table component, and you’ll also need to supply a column key which makes sense for your given data. I’ve found that approaches like this benefit from your table having a unique identifier for each row, or the logic can be modified to handle something akin to a combined key where you check against multiple columns.

1 Like

Thank you. I am getting the error:

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File “function:runAction”, line 7, in runAction
TypeError: ‘int’ object is not iterable

caused by org.python.core.PyException

Traceback (most recent call last):
File “function:runAction”, line 7, in runAction
TypeError: ‘int’ object is not iterable

Ignition v8.1.0 (b2020110211)
Java: Azul Systems, Inc. 11.0.7

while using the code:

current_data = self.getSibling("Table").props.data
rows_to_remove = self.getSibling("Table").custom.ID
known_colum_key = 'id'
rows_to_keep = []
unique_values_to_remove_on_match = [row[known_colum_key] for row in rows_to_remove]
for row in current_data:
	if row[known_colum_key] not in unique_values_to_remove_on_match:
		rows_to_keep.append(row)
self.getSibling('Table').props.data = rows_to_keep

I am using a custom Property named ‘ID’ to get my id key from my table. (It does not show in, ‘rows_to_remove = self.getSibling(‘Table’).props.selection.data’).

This is the code for that:

What am I doing wrong?

The error you’re getting tells me that there’s been a disconnect about how to use the code I provided. The code I provided belongs in a button component which is a sibling of the Table component.
Screen Shot 2020-12-31 at 8.55.40PM
You’re seeing the error because something you’ve done has resulted in the data of the Table becoming an int, and so when the script attempts to iterate over current_data, you are encountering the TypeError. It’s not possible from the information you’ve provided to discern how the data property entered such a state.

I’ve attached a View where this is working so that you can perhaps more clearly see how this should be set up.
RowDeleteExample.zip (26.8 KB)

I ended up just creating a named Query and passed a parameter into the Named Query.

params = {“ID”:self.getSibling(“Table”).custom.ID}
system.db.runNamedQuery(“Delete”, params)
self.getSibling(“Table”).refreshBinding(‘props.data’)
self.parent.parent.getChild(“FlexContainer_2”).getChild(“PDFViewer”).props.source = “”

Hi @cmallonee, your code is work fine for me but currently I want to delete the database at the same time. May I know how can I do ? I have tried many ways but it cant work for me.

Hi @cmallonee

I want to do the similar feature only difference is button from which to delete the row is in different view and trying to get table data in button view but not succeed as of now.
Can you help on this

Thanks

You will need to use system.perspective.sendMessage() with a message handler on the view which contains the table.

https://docs.inductiveautomation.com/display/DOC81/system.perspective.sendMessage