# Delete data from dataset vision

**URL:** <https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [November 20, 2023, 2:04pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127 "2023-11-20T14:04:17Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [November 20, 2023, 2:04pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/1 "2023-11-20T14:04:17Z")

</div>

hello, I need delete my data from table.  
Want I want is, when I select a row, and I click into DELETE button, row into table must be deleted

**code of delete button:**

```auto
tableData = event.source.parent.getComponent('Table').data
row = event.source.parent.row
if row != -1: 
   system.dataset.deleteRow(tableData, row)
else:
	system.gui.messageBox("select row!")

```

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

**Event into table** :

```auto
event.source.parent.row = event.source.selectedRow

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1be8a3843e4c9adf0d3ff70272d0775bcb99f7c8.png)

But when I click on the DELETE nothing is happening. Am I forgetting something about the syntax to delete row from table?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 20, 2023, 2:14pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/2 "2023-11-20T14:14:18Z")

</div>

The system function you are calling creates a new dataset without the deleted row. The new dataset has to be assigned back to the table's data property.

```auto
newData = system.dataset.deleteRow(tableData, row)
event.source.parent.getComponent('Table').data = newData
```

---

<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:** [November 20, 2023, 2:17pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/3 "2023-11-20T14:17:46Z")

</div>

There are a few errors here:

1. `row = event.source.parent.row`  
the event is the action performed, its source is the button, and the button's parent is NOT the table.  
I'm not sure how you got that path... try `row = event.source.parent.getComponent('Table').selectedRow`
2. datasets manipulation functions return NEW datasets. So you're not really deleting a row from your dataset, only creating a new one with that row removed, and then doing nothing with it.  
try `	event.source.parent.getComponent('Table').data = system.dataset.deleteRow(data, row)`
3. What's that `cellEdited` event supposed to do ? You don't need that.

---

<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:** [November 20, 2023, 2:33pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/4 "2023-11-20T14:33:46Z")

</div>

Along, with what @justinedwards.jle and @pascal.fragnoud have said, it should be noted that if the source of the data in your table is coming from a binding, then you need to also remove the row from source data, otherwise the binding will just overwrite any change that you have made.

In that instance I would say that you should actually remove the row from the source and then refresh the binding.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [November 20, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/5 "2023-11-20T15:19:46Z")

</div>

> [@pascal.fragnoud](#):
>
> What's that `cellEdited` event supposed to do ? You don't need that.

an event to tell me that I click on a row in the table.

Afterwards I don't really know if it's the right event that I chose

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [November 20, 2023, 3:28pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/6 "2023-11-20T15:28:10Z")

</div>

> [@sebastien\_ng](#):
>
> an event to tell me that I click on a row in the table.

I would use a property change script that looks at any change of the Selected Row property.

```auto
if event.propertyName == 'selectedRow':

```

`cellEdited` is for when you want to allow the user to edit the data on a cell, it would fire when the user finishes editing.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [November 20, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/7 "2023-11-20T15:34:37Z")

</div>

> [@lrose](#):
>
> Dans ce cas, je dirais que vous devez réellement supprimer la ligne de la source, puis actualiser la liaison.

Yes, normally the information on the table will come from an SQL query, but for now, I just want to retrieve the value of the row ID I clicked.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [November 20, 2023, 3:39pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/8 "2023-11-20T15:39:54Z")

</div>

> [@leonardo.godoi](#):
>
> `if event.propertyName == 'selectedRow':`

I did it:

```auto
if event.propertyName == 'selectedRow':
	event.source.parent.row = event.source.selectedRow + 1

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/db4c6ea75556643eb4bafa59ca55c31a3ea272c8.png)

it work, I can get value of ID column but it is incorrect in case of image below:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/5/05bf0d10964025e660cc844bfff85824ae61789f.png)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 20, 2023, 3:45pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/9 "2023-11-20T15:45:26Z")

</div>

The selected row will be zero indexed just like the table. I don't normally see developers adding a 1 to it. For deleting rows, this step isn't needed, but I'm imagining that you are doing other things with this property.

For deleting selected rows from a button, the whole script should look like this:

```auto
# Get the table, its data property, and the selected row
table = event.source.parent.getComponent('Table')
tableData = table.data
row = table.selectedRow

# if a row is selected, create a dataset without the row
# ...and assign it back to the table's data property.
if row != -1:
	table.data = system.dataset.deleteRow(tableData, row)

```

I've excluded the message box `else` clause from your original post. Personally, I don't like them because they are gui locking. I would go with a label or some other indicator for that purpose.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [November 20, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/10 "2023-11-20T15:52:58Z")

</div>

> [@justinedwards.jle](#):
>
> ```auto
> table = event.source.parent.getComponent('Table')
> tableData = table.data
> row = table.selectedRow
> if row != -1:
> table.data = system.dataset.deleteRow(tableData, row)
> 
> ```

yes,I can delete data using this script into delete button. but I also read ID value of column ID when I clique in row

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 20, 2023, 3:56pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/11 "2023-11-20T15:56:36Z")

</div>

> [@sebastien\_ng](#):
>
> also read ID value of column ID

This is all you have to add:

```auto
rowID = tableData.getValueAt(row, 'ID')

```

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [November 20, 2023, 4:02pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/12 "2023-11-20T16:02:36Z")

</div>

I dit it:

```auto
if event.propertyName == 'selectedRow':
	#event.source.parent.row = event.source.selectedRow + 1
	table = event.source.parent.getComponent('Table')
	tableData = table.data
	row = table.selectedRow
	event.source.parent.row = tableData.getValueAt(row, 'ID')

```

Andd I get it 😃  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/b/ab503a9da6a445c1473ce90746bf6a76dfd6129d.png)

it is Okay now

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 20, 2023, 4:04pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/13 "2023-11-20T16:04:36Z")

</div>

> [@sebastien\_ng](#):
>
> it is Okay now

Excellent. One other thing: on your table's propertyChange event handler, this line:

```auto
table = event.source.parent.getComponent('Table')

```

could be simplified to this:

```auto
table = event.source

```

---

<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:** [November 20, 2023, 4:09pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/14 "2023-11-20T16:09:09Z")

</div>

Or remove the script entirely and put that binding on the label:

```auto
try(
	{Root Container.Table.data}[{Root Container.Table.selectedRow}, 'ID'],
	-1
)

```

---

<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:** [November 20, 2023, 4:24pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/15 "2023-11-20T16:24:18Z")

</div>

![ID space](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/3/b37e9cd70afdfe6c185b23e82122fc05e72f6d2f.png)

I see a space after 4 (`'4 '`) in the ID column. It suggests that your ID is a string where maybe the column should be an Int to prevent a problem that may bite you in the future.

---

<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:** [November 20, 2023, 4:27pm UTC](https://forum.inductiveautomation.com/t/delete-data-from-dataset-vision/82127/16 "2023-11-20T16:27:44Z")

</div>

I think he just clicked on that cell, which makes it look like this.  
The right alignment suggests it is indeed an int.

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

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d00b0619eef1a174f060308a4a7049c392e080a3.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d014055a5b777c8fdc82353939be42e8407802f7.png)
