# Delete Selected Rows From Table In Perspective?

**URL:** <https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880>\
**Category:** Ignition\
**Created:** [December 31, 2020, 5:08pm UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880 "2020-12-31T17:08:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![awarunek187](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@awarunek187](https://forum.inductiveautomation.com/u/awarunek187)\
**Post date:** [December 31, 2020, 5:08pm UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/1 "2020-12-31T17:08:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 31, 2020, 6:21pm UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/2 "2020-12-31T18:21:30Z")

</div>

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):

```auto
	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.

---

<div class="post-metadata">

**Author:** ![awarunek187](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@awarunek187](https://forum.inductiveautomation.com/u/awarunek187)\
**Post date:** [December 31, 2020, 7:53pm UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/3 "2020-12-31T19:53:47Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/7/472885806e4d99e4fc7e8054f5acaf6a8e47fe70.png)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 1, 2021, 4:58am UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/4 "2021-01-01T04:58:43Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/8/685c4b202f47271bcbf0075f8a292ed000dcffaa.png)  
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](https://forum.inductiveautomation.com/uploads/short-url/nqYPV5taFUtUH1CPnkEnDhqEIHe.zip) (26.8 KB)

---

<div class="post-metadata">

**Author:** ![awarunek187](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@awarunek187](https://forum.inductiveautomation.com/u/awarunek187)\
**Post date:** [January 12, 2021, 8:24pm UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/5 "2021-01-12T20:24:32Z")

</div>

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 = “”

---

<div class="post-metadata">

**Author:** ![tohhy-pm17](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tohhy-pm17](https://forum.inductiveautomation.com/u/tohhy-pm17)\
**Post date:** [March 31, 2021, 4:29am UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/6 "2021-03-31T04:29:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [April 13, 2022, 11:21am UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/7 "2022-04-13T11:21:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 13, 2022, 2:41pm UTC](https://forum.inductiveautomation.com/t/delete-selected-rows-from-table-in-perspective/41880/8 "2022-04-13T14:41:00Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC81/system.perspective.sendMessage)
