# Perspective table delete row

**URL:** <https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [February 12, 2021, 12:07am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338 "2021-02-12T00:07:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick4](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nick4](https://forum.inductiveautomation.com/u/nick4)\
**Post date:** [February 12, 2021, 12:07am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/1 "2021-02-12T00:07:14Z")

</div>

I have a table in Perspective that the client would like to be able to delete entries from. Initially I accomplished this through an onCellEdited script by getting the dataset, deleting the row, and setting the table data equal to the modified dataset, and it worked well. The client has now requested to be able to delete entries with a button, so I used a very similar script, but every time I try to delete the lowest row in the set, it errors the component. I’m not really sure of what the problem may be, as a near identical script worked in the onCellEdited script. Is there something I’m missing here?

 ![dataEntryError](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/58cec9cf749a07db22f374926a3c0a7d0e659b93.jpeg)  
 ![dataEntryDeleteScript](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/907e9985c979e1e7e59f7cec882f2a54da5e2767.jpeg)

---

<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:** [February 12, 2021, 3:22am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/2 "2021-02-12T03:22:09Z")

</div>

In looking at the documentation for [dataset.deleteRow](https://docs.inductiveautomation.com/display/DOC81/system.dataset.deleteRow), you’re passing an argument of an unexpected type. You’re supplying an object which defines the values of the row, whereas the function `deleteRow` expects an `int` index of the row to delete. You’ll need to loop through the dataset to determine which row is selected from the data you have in `row`.

---

<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:** [May 23, 2022, 9:39am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/3 "2022-05-23T09:39:21Z")

</div>

Hi @cmallonee,

the same delete function i tried to use on button on click event. I am doing 2 events on button click 1) open popup 2) delete the selected row.  
I am able to open popup and delete the table but after 10-20sec the deleted row value gets back in table. I am polling off also but dont know why is it happening also i am using Oracle database for query data. My application is to delete the row from view table but now from database.

---

<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:** [May 23, 2022, 2:52pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/4 "2022-05-23T14:52:40Z")

</div>

Please supply your code for the deletion.

---

<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:** [May 24, 2022, 5:28am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/5 "2022-05-24T05:28:55Z")

</div>

I am attaching onclick event code and query binding. The database used is oracle and the date variable used in named query will take data from last 7 days.

 ![button script](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28a179f6375ffb14a10dba927b36aea0cd18d549.png)  
 ![Query binding oracle](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/3/d3a14e71e9c9365edbbbf52367b884340684c795.png)

---

<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:** [May 24, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/6 "2022-05-24T12:55:06Z")

</div>

You’re deleting the row from the dataset, but that is not the same as deleting it from the database. Your query only selects the data, and since you haven’t removed the row from the database, when the query gets run again, the row “reappears” in the table.

Ignition Dataset is not equal to database table.

When you remove the row from the dataset in your script you need to also remove the row from the database, either through a `system.db.runPrepUpdate` or a `system.db.runNamedQuery`.

---

<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:** [May 24, 2022, 12:59pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/7 "2022-05-24T12:59:33Z")

</div>

Hi,  
I dont want to delete the data from database but only from view table data as the operator need to know that the data he has deleted is sent to MES thats why i am doing the delete function. do you have any other solution to notify operator that data is sent or is already being sent

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 24, 2022, 1:11pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/8 "2022-05-24T13:11:06Z")

</div>

Then don’t use a query binding to populate the table. Its whole purpose is to display data from the database. You will need to _ **script** _ a suitable state machine that initializes an intermediate property **once** from the database, then all further manipulations work with that property.

---

<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:** [May 24, 2022, 1:35pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/9 "2022-05-24T13:35:56Z")

</div>

So, i need to use named query in session custom property and then use it anywhere but i have date used to filter so will it update the dummy data or i need to do it separately

---

<div class="post-metadata">

**Author:** ![Farhan\_Basheer](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/farhan_basheer/32/66759_2.png) [@Farhan\_Basheer](https://forum.inductiveautomation.com/u/Farhan_Basheer)\
**Post date:** [September 7, 2024, 2:25pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/10 "2024-09-07T14:25:51Z")

</div>

This is how I would do it.

```python
def runAction(self, event):
    tbl_assets = self.getSibling("Tbl_Assets")
    data = tbl_assets.props.data
    selected_row = tbl_assets.props.selection.selectedRow

    # Check if a row is selected
    if selected_row is not None:
        # Get the column names from the first row (assuming all rows have the same structure)
        columns = list(data[0].keys())
        
        # Extract the rows as a list of lists (instead of a list of dictionaries)
        rows = [[row[col] for col in columns] for row in data]

        # Create the dataset from the columns and rows
        dataset = system.dataset.toDataSet(columns, rows)

        # Delete the selected row from the Dataset
        dataset = system.dataset.deleteRow(dataset, selected_row)

        # Convert the updated Dataset back to a list of dictionaries
        pyDataSet = system.dataset.toPyDataSet(dataset)
        
        # Ensure correct conversion by explicitly creating dictionaries from the dataset
        data_list = [{columns[i]: row[i] for i in range(len(columns))} for row in pyDataSet]
        
        # Update the table data with the new list (row removed)
        tbl_assets.props.data = data_list
        
        # Reset the selected row
        tbl_assets.props.selection.selectedRow = None
    else:
        # Handle case when no row is selected (optional)
        system.perspective.print("No row selected for deletion")

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 7, 2024, 4:01pm UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/11 "2024-09-07T16:01:56Z")

</div>

> [@Farhan\_Basheer](#):
>
> ```python
> rows = [[row[col] for col in columns] for row in data]
> 
> ```

use this instead

```python
rows = [row.values() for row in data]

```

edit: wait, you're converting the whole thing to a dataset just to delete a row, then converting back to a list of dicts ?

Just put this in a "`delete_selected_row`" script on the table:

```python
def runAction(self, event):
	if self.props.selection.selectedRow is not None:
		self.props.data.pop(self.props.selection.selectedRow)

```

Then call this script from whatever button or event:

```python
def runAction(self, event):
	self.getSibling("Tbl_Assets").delete_selected_row()

```

Though I'd probably open a confirmation popup on click, then send a `delete_row` message back to the table.

---

<div class="post-metadata">

**Author:** ![Farhan\_Basheer](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/farhan_basheer/32/66759_2.png) [@Farhan\_Basheer](https://forum.inductiveautomation.com/u/Farhan_Basheer)\
**Post date:** [September 8, 2024, 8:31am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/12 "2024-09-08T08:31:21Z")

</div>

`opening a confirmation popup` is already giving me a hard time 😄

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 8, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/perspective-table-delete-row/43338/13 "2024-09-08T09:18:05Z")

</div>

> [@Farhan\_Basheer](#):
>
> `ystem.dataset.deleteRow(dataset, selected_row)`

Here's an example project with a table and 2 buttons to remove the selected row from that table, one with a confirm popup and one without.  
[delete\_row.zip](https://forum.inductiveautomation.com/uploads/short-url/oMIdGrREI4lgUpvFN8KrKakRWLb.zip) (53.6 KB)

I changed the delete function a bit to handle both datasets and lists of dicts.  
The confirmation popup is my standard one, the same one I sent you before, so it has a few parameters that aren't used here but I wasn't gonna make a new one just for this.
