# Retain Background Color Mapping of a Table for new dataset

**URL:** <https://forum.inductiveautomation.com/t/retain-background-color-mapping-of-a-table-for-new-dataset/10330>\
**Category:** General Discussion\
**Created:** [August 11, 2015, 3:15am UTC](https://forum.inductiveautomation.com/t/retain-background-color-mapping-of-a-table-for-new-dataset/10330 "2015-08-11T03:15:43Z")\
**Posts on this page:** 3\
**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:** [August 11, 2015, 3:15am UTC](https://forum.inductiveautomation.com/t/retain-background-color-mapping-of-a-table-for-new-dataset/10330/1 "2015-08-11T03:15:43Z")

</div>

Hi all,

Is there a way in Ignition Script to retain Background Color Mapping of a Table?

Here is the scenario, I created a table in Ignition with a background color mapping depending on "priority" value of a row where "priority" is one of its columns.

Then, I created a script in one of the components (a button) where the table's dataset will be replaced with new a dataset (but having its column names retained) when the script is ran. When I did that, the table's dataset is replaced but the background color mapping is gone! Is there a way to retain the background color mapping when the dataset is replaced?

Here is part of my script:

table = event.source.parent.getComponent('Debug Table')  
headers = list(table.data.getColumnNames()) #to retain the column names  
dataOut = []  
table.data = system.dataset.toDataSet(headers, dataOut)  
tableData = table.data

for i in range(len(datetimeList)): #datetime, priority, and message lists are defined earlier   
 tableData = system.dataset.addRow(tableData, i, [datetimeList[i], priorityList[i], messageList[i]])  
table = event.source.parent.getComponent('Debug Table')  
table.data = tableData

This question is related to my earlier post: [https://inductiveautomation.com/forum/viewtopic.php?f=50&t=14191](https://inductiveautomation.com/forum/viewtopic.php?f=50&t=14191)

Many thanks!

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 11, 2015, 5:23am UTC](https://forum.inductiveautomation.com/t/retain-background-color-mapping-of-a-table-for-new-dataset/10330/2 "2015-08-11T05:23:54Z")

</div>

Hi ian,

I am not sure why your background mapping is getting lost. Your code does not show why.

I would write your code like this:

```auto
rows = []
for i in range(len(datetimeList)):
	rows.append([datetimeList[i], priorityList[i], messageList[i]])
table = event.source.parent.getComponent('Debug Table')
table.data = system.dataset.toDataSet(list(table.data.getColumnNames()),rows)
```

I wonder if you are accidentally changing the datatype of the column that the background mapping is using. The mapping only works on a column that is a number – does not work for strings.

Since you are working with datasets you might be interested in the [MutablePyDataSet](http://nickmudge.info/post/pa-power-scripting-module#MutablePyDataSet).

Best,

---

<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:** [August 11, 2015, 6:38am UTC](https://forum.inductiveautomation.com/t/retain-background-color-mapping-of-a-table-for-new-dataset/10330/3 "2015-08-11T06:38:58Z")

</div>

Hi nmudge,

You are right, it seems like I accidentally change the column data type from integer to string in the process. Could it be caused by:

```auto
tableData = system.dataset.addRow(tableData, i, [datetimeList[i], priorityList[i], messageList[i]])
```

?

When I use your example, everything is okay. Thanks!
