# Deleting row/s from table

**URL:** <https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049>\
**Category:** Ignition\
**Tags:** database, ignition81, perspective\
**Created:** [May 22, 2023, 11:50pm UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049 "2023-05-22T23:50:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adela\_Zumrova](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Adela\_Zumrova](https://forum.inductiveautomation.com/u/Adela_Zumrova)\
**Post date:** [May 22, 2023, 11:50pm UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/1 "2023-05-22T23:50:12Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/e/6ed138bd9bb5d6f1c2a5364284250c916e508318.png)

Newbie question, please bear with me. I have a table with data in it, the last column has delete and edit buttons against each row of table, which are embedded from another view.  
What is the most simple/easiest way to delete a row (obviously after pressing the delete button) here and in the DB. The ID is the key value and I have assigned them randomly. Thank You

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [May 23, 2023, 12:50am UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/2 "2023-05-23T00:50:14Z")

</div>

You can bind the viewParams to **this.props.selection**. when you click the button, you select the cell, and the embedded view get the params. After that, you get a target to operate on.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/4/9455d9996863508cd4b95f2f4f8c2ddb7a46fa9a.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 23, 2023, 6:11pm UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/3 "2023-05-23T18:11:57Z")

</div>

> [@Adela\_Zumrova](#):
>
> What is the most simple/easiest way to delete a row ... here and in the DB.

- By default, the embedded view will receive a parameter `rowData` which contains all the data in the row. In your case you are only interested in the `ÌD` value.
- On the embedded view you need to manually add `params.custom.rowData`.
- Right-click on the delete button, select _Configure Events_, \*onActionPerformed`, add a script and add the code below (indenting one tab).

```auto
def runAction(self, event):
    # Delete the record.
    system.db.runPrepUpdate('DELETE FROM config WHERE id = ?', [self.view.params.rowData['ID']])
    # Send a message to anything that's listening.
    system.perspective.sendMessage("dataTableChanged", payload = {}, scope = "session")

```

- Right-click on the table to be updated, select _Configure Scripts_, add a message handler, call it `dataTableChanged" (exactly the same as in the sendMessage routine), set the listen scopes to "Session" and enter the following code.

```auto
def onMessageReceived(self, payload):
    self.refreshBinding("props.data")

```

---

<div class="post-metadata">

**Author:** ![Adela\_Zumrova](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Adela\_Zumrova](https://forum.inductiveautomation.com/u/Adela_Zumrova)\
**Post date:** [July 3, 2023, 9:23am UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/4 "2023-07-03T09:23:43Z")

</div>

Thank You, I made that work after couple of tries.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 3, 2023, 9:30am UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/5 "2023-07-03T09:30:07Z")

</div>

Just for making things easier for yourself in the future.

I would not let the delete be handled on the button action.  
instead also send a message (similar to "dataTableChanged" )  
"deleteRow" or something with the id as payload

And handle the delete on the message handler

This way you can use the same delete/edit button subview for other tables. you'll just have to put another message handler on it

---

<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:** [July 3, 2023, 10:11am UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/6 "2023-07-03T10:11:21Z")

</div>

I'll suggest another way of doing this:  
Don't put a delete button on each row, instead add a `remove selected row` outside of the table.  
Then use the table's `props.selection.selectedRow` to delete that row when the button is clicked.  
You can use the `selection.data` property to update the database at the same time.  
Or add another `update database` button to do batch updates.

This removes the need for subviews, message handlers, etc.  
You can even allow multiple selection to remove multiple rows at once.  
And you can reuse the mechanism for any other table, all you have to do is copy/paste the button and update the path to the table component.

The button script is as simple as this:

```python
row_id = self.getSibling("Table").props.selection.selectedRow
row = self.getSibling("Table").props.data.pop(row_id)
system.db.runNamedQuery("remove_row", parameters=row)

```

---

<div class="post-metadata">

**Author:** ![Derek\_Porter](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Derek\_Porter](https://forum.inductiveautomation.com/u/Derek_Porter)\
**Post date:** [June 7, 2024, 12:43pm UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/7 "2024-06-07T12:43:32Z")

</div>

In the "row = self.getSibling("Table").props.data.pop(row\_id)" what is the pop representing?

---

<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:** [June 7, 2024, 2:06pm UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/8 "2024-06-07T14:06:30Z")

</div>

pop is a function which removes the row from the `table.props.data` with row\_id and returns it.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 7, 2024, 4:30pm UTC](https://forum.inductiveautomation.com/t/deleting-row-s-from-table/74049/9 "2024-06-07T16:30:27Z")

</div>

`pop()` with a "Try it yourself".

> **[W3Schools.com](https://www.w3schools.com/python/ref_list_pop.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
