# Ignition 8.1.5 - Perspective Table - How to populate Data Property (Dataset vs JSON)?

**URL:** <https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281>\
**Category:** Ignition\
**Created:** [May 31, 2021, 4:21pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281 "2021-05-31T16:21:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mudbay](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mudbay](https://forum.inductiveautomation.com/u/mudbay)\
**Post date:** [May 31, 2021, 4:21pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/1 "2021-05-31T16:21:27Z")

</div>

I have been reviewing other forum threads on this, but can’t seem to find good “guidance” on how best to work with the **Perspective Table Component** when it comes to mapping data to the **Data** property in the component… The easiest method I have found to populate the **Data** property of the **Table**  **Component** is using **Datasets** , however, in this format it seems to be inflexible in terms of being able to edit cells, change colors etc. vs a pure JSON object. (See illustration).

My question to the forum users and experts that have used this Component is:

1. If you are querying data from a database to subsequently display in a **Table**  **Component** , the most common return object from a **Named Query** is a **Dataset**. How do you manipulate a Dataset to add properties to make fields “Editable” or change colors etc. like you can with a pure JSON object.
2. Is there a easy way to return a JSON object from a query that would map more readily into the Data property that would make it easier to than manipulate and Append properties like “editable” and “style”?

Many thanks in advance to the community for there advice.

 ![Ignition Support Drawings (5)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/75b231e2a283939ea9f863abb039886cb447df33.jpeg)

---

<div class="post-metadata">

**Author:** ![mudbay](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mudbay](https://forum.inductiveautomation.com/u/mudbay)\
**Post date:** [May 31, 2021, 5:29pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/2 "2021-05-31T17:29:45Z")

</div>

I think (perhaps) part of the solution may lie in the following code to transform datasets to dictionaries. I will look into this more and see where this leads:

`# convert the incoming value data`

`pyData ` `=` `system.dataset.toPyDataSet(value)`  
`# get the header names`  
`header ` `=` `pyData.getColumnNames()`  
`# create a blank list so we can append later`  
`newList ` `=` `[]`  
`# step through the rows`  
`for` `row ` `in` `pyData:`  
` ` `# create a new blank dictionary for each row of the data`  
` ` `newDict ` `=` `{}`  
` ` `# use an index to step through each column of the data`  
` ` `for` `i ` `in` `range` `(` `len` `(row)):`  
` ` `# set name/value pairs`  
` ` `newDict[header[i] ] ` `=` `row[i]`  
` `  
` ` `# append the dictionary to list`  
` ` `newList.append(newDict)`  
` `  
`# return the results`  
`return` `newList`

Reference: [Script Transform - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Script+Transform)

---

<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 31, 2021, 7:30pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/3 "2021-05-31T19:30:25Z")

</div>

Bind against the dataset you want to use, then apply a script transform in this shape:

```auto
    py_data = system.dataset.toPyDataSet(value)
	data = []
	headers = py_data.getColumnNames()
	row_count = py_data.getRowCount()
	for i in range(row_count):
		row_dict = {}
		for header in headers:
			row_dict[header] = py_data.getValueAt(i, header)
		data.append(row_dict)
	return data

```

This will convert your dataset into what is essentially a json object.

---

<div class="post-metadata">

**Author:** ![mudbay](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mudbay](https://forum.inductiveautomation.com/u/mudbay)\
**Post date:** [May 31, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/4 "2021-05-31T19:43:22Z")

</div>

Thanks.

Have utilized this approach and it seems to be working.

---

<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:** [June 1, 2021, 4:13pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/5 "2021-06-01T16:13:40Z")

</div>

Although, if you’re using a query binding, you can just change the return format to `json` - you don’t need to bring in as a dataset and then attempt to convert.

---

<div class="post-metadata">

**Author:** ![thecesrom.git](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@thecesrom.git](https://forum.inductiveautomation.com/u/thecesrom.git)\
**Post date:** [August 6, 2022, 12:20am UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/6 "2022-08-06T00:20:27Z")

</div>

Not sure if overkill or not, but I have added a function in [`incendium`](https://github.com/thecesrom/incendium) to transform Datasets, even those with nested Datasets if it were to be the case (see [wiki](https://github.com/thecesrom/incendium/wiki/incendium.dataset.to_jsonobject)) “into what is essentially a json object”.

Expect it on version 2022.8.2 in [Ignition Exchange](https://inductiveautomation.com/exchange/2104/overview), or you may just clone the [`project`](https://github.com/thecesrom/incendium/tree/project) branch under your `{IGNITION_DIR}/data/projects` directory (instructions can be found [here](https://github.com/thecesrom/incendium/tree/project#cloning-this-branch)), or download the ZIP file from [Releases](https://github.com/thecesrom/incendium/releases) and install it on your Gateway.

And remember, PRs are welcome.

---

<div class="post-metadata">

**Author:** ![Cristian\_Gomez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cristian_gomez/32/49040_2.png) [@Cristian\_Gomez](https://forum.inductiveautomation.com/u/Cristian_Gomez)\
**Post date:** [July 10, 2023, 5:24pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/7 "2023-07-10T17:24:28Z")

</div>

Hi PGriffith  
What happens is that I have 2 datasets that I bring directly from the database, these datasets have respectively the information that I want to show in the table and the backgrount color for each cell in a particular way, the datasets are 1500Rx37C but when I apply a script to read the color data that I want to place in each cell and then transform to JSON, Ignition stops working and I get error of limitation of columns in the loop, how I could solve this to print the colors that I have in the datase.  
This is the code:

```auto
def perspectiveTableConfig(tableDataFilt, tableConfigFilt):
	py_data = system.dataset.toPyDataSet(tableDataFilt)
	py_config = system.dataset.toPyDataSet(tableConfigFilt)
	data = []
	
	default_style = {"background": "lightgray"} # Default color for cells without style value
	alternate_style = {"background": "white"} # Alternate color for cells with no style value
	
	for i in range(py_data.getRowCount()):
	    row_dict = {}
	    for j, header in enumerate(py_data.getColumnNames()):
	        cell_value = py_data.getValueAt(i, j)
	        cell_style = py_config.getValueAt(i, j)
	
	        # Check if the style is empty and toggle between the default color and the alternate color.
	        if not cell_style:
	            if i % 2 == 0:
	                cell_style = default_style
	            else:
	                cell_style = alternate_style
	
	        cell_obj = {"value": cell_value, "style": cell_style}
	        row_dict[header] = cell_obj
	    data.append(row_dict)
	
	return data

```

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [July 10, 2023, 5:40pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/8 "2023-07-10T17:40:58Z")

</div>

I think the final version of this is going to use list comprehension, zip, and CSS styles...  
In the meantime, you don't need to getColumnNames for each row - do that once outside the outer loop.  
You are using pyDataSets so I think you can address cell\_value as py\_data[i,j]  
And probably a few more things to make it pythonic.

---

<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 10, 2023, 6:11pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/9 "2023-07-10T18:11:43Z")

</div>

> [@Cristian\_Gomez](#):
>
> gnition stops working and I get error of limitation of columns in the loop

This seems contradictory. What does 'stops working' mean (for example, _what_ stops working, and how do you know what error you're getting if it stops working?)

Exact error details, including the stacktrace, are infinitely valuable if you've got it.

---

<div class="post-metadata">

**Author:** ![Cristian\_Gomez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cristian_gomez/32/49040_2.png) [@Cristian\_Gomez](https://forum.inductiveautomation.com/u/Cristian_Gomez)\
**Post date:** [July 10, 2023, 6:19pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/10 "2023-07-10T18:19:32Z")

</div>

> [@paul-griffith](#):
>
> This seems contradictory. What does 'stops working' mean (for example, _what_ stops working, and how do you know what error you're getting if it stops working?)
> 
> Exact error details, including the stacktrace, are infinitely valuable if you've got it.

You are right, the error I get is this " [java.lang.ArrayIndexOutOfBoundsException] ", but I get it when I reduce the columns I am evaluating, when I work with the full size dataset it just closes the designer.

---

<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 10, 2023, 6:21pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/11 "2023-07-10T18:21:16Z")

</div>

> [@Cristian\_Gomez](#):
>
> ArrayIndexOutOfBoundsException

From the snippet above, the only way I can see that getting thrown is if the row or column indices are out of bounds for one of your input datasets.

---

<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:** [July 10, 2023, 7:33pm UTC](https://forum.inductiveautomation.com/t/ignition-8-1-5-perspective-table-how-to-populate-data-property-dataset-vs-json/47281/12 "2023-07-10T19:33:31Z")

</div>

Agreed. This code assumes `tableDataFilt` and `tableConfigFilt` are datasets of the exact same dimensions. As you're using the expected indices of `tableConfigFilt`, it's highly likely that `tableConfigFilt` either has fewer rows, or fewer columns.
