# \[SOLVED\] Download filtered Perspective table component data

**URL:** <https://forum.inductiveautomation.com/t/solved-download-filtered-perspective-table-component-data/76255>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 12, 2023, 1:34pm UTC](https://forum.inductiveautomation.com/t/solved-download-filtered-perspective-table-component-data/76255 "2023-07-12T13:34:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 12, 2023, 1:34pm UTC](https://forum.inductiveautomation.com/t/solved-download-filtered-perspective-table-component-data/76255/1 "2023-07-12T13:34:21Z")

</div>

Good morning,

I have a Perspective button that executes this onActionPerformed event which takes data from a perspective table and outputs a CSV file to the local download folder.

```auto
ds = self.parent.parent.getChild("tbl_Data").props.data
csv = system.dataset.toCSV(dataset = ds, showHeaders = True, forExport = False)
system.perspective.download("test.csv", csv)
```

This code works fine. However, when I filter the results using the built in table filter the above code returns all the dataset still. So I changed the code below to only look at the filter results:

```auto
ds = self.parent.parent.getChild("tbl_Data").props.filter.results.data
csv = system.dataset.toCSV(dataset = ds, showHeaders = True, forExport = False)
system.perspective.download("test.csv", csv)
```

However, this new code is returning an empty file:

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

Is this a bug? Or am I looking at the wrong place for the data? Or am I not going about this process correctly?

Any advice is appreciated.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 12, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/solved-download-filtered-perspective-table-component-data/76255/2 "2023-07-12T14:43:46Z")

</div>

> [@bmeyers](#):
>
> `self.parent.parent.getChild("tbl_Data").props.filter.results.data`

This isn't a dataset anymore, even if the input is. It's a JSON-array-like structure. You need to normalize it back into a dataset yourself.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 12, 2023, 3:48pm UTC](https://forum.inductiveautomation.com/t/solved-download-filtered-perspective-table-component-data/76255/3 "2023-07-12T15:48:13Z")

</div>

Ok.

First issue was I had to enable the filter in the settings which allowed the results to be stored in the results below.

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

And then I had to convert the JSON-array-like structure (that could totally just be a dataset but I'm not complaining...) using the following code:

```auto
import ast

ds = str(self.parent.parent.getChild("tbl_Data").props.filter.results.data)

# Extract the content within "<ArrayWrapper>: [...]"
data_string = ds[ds.index("["):].replace("u'", "'")

# Parse the string into a list of dictionaries
data_list = ast.literal_eval(data_string)

# Extract the headers
headers = list(data_list[0].keys())

# Extract the data rows
data = [list(d.values()) for d in data_list]

ds = system.dataset.toDataSet(headers, data)
csv = system.dataset.toCSV(dataset = ds, showHeaders = True, forExport = False)

system.perspective.download("test.csv", csv)
```

Thank you for the help.

---

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [July 12, 2024, 2:00am UTC](https://forum.inductiveautomation.com/t/solved-download-filtered-perspective-table-component-data/76255/4 "2024-07-12T02:00:36Z")

</div>

I have Chinese in column 3, how to encode it?  
`Caused by: org.python.core.PyException: TypeError: Unable to convert row 1, column 3 to type class java.lang.Integer`

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