Retain Background Color Mapping of a Table for new dataset

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

Many thanks!

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:

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.

Best,

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:

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

?

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