# Deleting all rows in a Dataset (except its header) by Script

**URL:** <https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268>\
**Category:** General Discussion\
**Created:** [July 24, 2015, 1:39pm UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268 "2015-07-24T13:39:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://forum.inductiveautomation.com/u/ian)\
**Post date:** [July 24, 2015, 1:39pm UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268/1 "2015-07-24T13:39:42Z")

</div>

Hi guys,

(This is my first post)

Is there any way in Ignition where we can delete all existing rows in a date set using a script?

I know system.dataset.deleteRows(dataset, rowIndices) can delete the rows in the dataset given the dataset and row indices. But if we were to delete all at once (except the header), is there an easier way?

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 24, 2015, 2:51pm UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268/2 "2015-07-24T14:51:12Z")

</div>

This should work on any dataset:

```python
ds = event.source.parent.getComponent('Table').data
headers = list(ds.getColumnNames())
dataOut=[]
event.source.parent.getComponent('Table').data=system.dataset.toDataSet(headers,dataOut)

```

EDIT: edited for forum change readability

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 24, 2015, 2:52pm UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268/3 "2015-07-24T14:52:28Z")

</div>

Sorry for my manners. Usually I welcome people first… 😊

Anyway, welcome to the forums! ![:mrgreen:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/d23659b203d2d24d394be983a52adb2fa6fe23d4.gif "Mr. Green")

---

<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:** [July 24, 2015, 3:44pm UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268/4 "2015-07-24T15:44:57Z")

</div>

Unfortunately, using toDataset() with an empty list won’t retain the column datatypes. For that, you need something like this:`from com.inductiveautomation.ignition.common import BasicDataset
ds = event.source.parent.getComponent('Table').data
ds0 = BasicDataset(ds.getColumnNames(), ds.getColumnTypes(), None)`

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://forum.inductiveautomation.com/u/ian)\
**Post date:** [July 27, 2015, 1:43am UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268/5 "2015-07-27T01:43:30Z")

</div>

Hi Jordan & pturmel,

Thanks! Those work! 😲 I am still new to Ignition, thus many things I got to figure out yet.

@Jordan: no worries about mannerism, you have helped me! 🙂

Regards,  
ian

---

<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:** [October 29, 2021, 2:25pm UTC](https://forum.inductiveautomation.com/t/deleting-all-rows-in-a-dataset-except-its-header-by-script/10268/6 "2021-10-29T14:25:05Z")

</div>

Split this topic on October 29, 2021, 2:25pm UTC

A post was split to a new topic: [Display custom message when Perspective Table has no data](https://forum.inductiveautomation.com/t/display-custom-message-when-perspective-table-has-no-data/52499)
