# Customizing Data in Perspective Table Component

**URL:** <https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [August 11, 2025, 5:22pm UTC](https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599 "2025-08-11T17:22:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjjones](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sjjones](https://forum.inductiveautomation.com/u/sjjones)\
**Post date:** [August 11, 2025, 5:22pm UTC](https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599/1 "2025-08-11T17:22:47Z")

</div>

Hello!

I have a toggle switch that records the start and end time of a “batch”. I have the times stored on a historized tags. I wanted to set up a table where you could select which start and end time you wanted and then that would select a report to print. However I keep getting weird double entries when I populate the table with the binding (I believe this has something to do with the time stamp). This is not good because it sets the start time after the end time and that shouldn’t work like that.

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

I could do the data editing in a script, but where should I attach the script to is my question. There’s a 100 different ways you could do this, but I figured I should ask the professionals before I make someone else’s life harder.

Let me know what you guys think!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 11, 2025, 5:39pm UTC](https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599/2 "2025-08-11T17:39:11Z")

</div>

This is a use case for a dropdown rather than a table, but let's work with the table for now.

Please show

- How the toggle switch is being recorded.
- The table data binding.

Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831) but post a screengrab as well if you think context would be helpful.

Welcome to the forum.

---

<div class="post-metadata">

**Author:** ![sjjones](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sjjones](https://forum.inductiveautomation.com/u/sjjones)\
**Post date:** [August 11, 2025, 6:57pm UTC](https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599/3 "2025-08-11T18:57:49Z")

</div>

I didn’t think of a drop down. Thanks. I would still like to see if this could work as intended though.

I have this script running as change script on the selected property of a toggle. Here’s the code:

```python
if self.props.selected == True:
	tag1 = system.tag.getConfiguration("[default]PressureTestV2/SimulatedCurrentPressure",0)
	tag2 = system.tag.getConfiguration("[default]PressureTestV2/SimulatedMaxPressure",0)
	tag1[0][u'historyEnabled'] = True
	tag2[0][u'historyEnabled'] = True
	system.tag.configure("[default]PressureTestV2",tag1) #could use merge overwrite
	system.tag.configure("[default]PressureTestV2",tag2)
	
	system.tag.writeBlocking("[default]PressureTestV2/BatchStarted",1)
	system.tag.writeBlocking("[default]PressureTestV2/StartTime",system.date.now()) # Forum! this line
if self.props.selected == False:
	tag1 = system.tag.getConfiguration("[default]PressureTestV2/SimulatedCurrentPressure",0)
	tag2 = system.tag.getConfiguration("[default]PressureTestV2/SimulatedMaxPressure",0)
	tag1[0][u'historyEnabled'] = False
	tag2[0][u'historyEnabled'] = False
	system.tag.configure("[default]PressureTestV2",tag1)
	system.tag.configure("[default]PressureTestV2",tag2)
	
	system.tag.writeBlocking("[default]PressureTestV2/BatchStarted",0)
	system.tag.writeBlocking("[default]PressureTestV2/EndTime",system.date.now()) # Forum! this line too

```

There’s some other stuff in here where I turn tags’ history on an off, and I do admit this might not be the best way to do this. For the stuff relevant to this post, I used the last lines of the if and else statement to write to the tags. I added comments saying which lines.

The tags (EndTime and StartTime) are just standard memory tags. Tags also might not be the best way to this either, but it’s just what I know right now.

Here’s the tag history binding on the table.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f6ccb001bf8e6532a9db01e9c5571c543695b0be.png)

In regards to the table, I have also added to the columns property to exclude the time stamp column. The problem is still there when I have the time stamp column.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 11, 2025, 7:11pm UTC](https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599/4 "2025-08-11T19:11:54Z")

</div>

I'm no Python expert, but a couple of pointers:

```python
if self.props.selected == True:
    # do stuff
if self.props.selected == False:
    # do other stuff

```

can be replaced by,

```python
if self.props.selected:
    # do stuff
else:
    # do other stuff

```

writeBlocking accepts lists (and even single values should be supplied as a list) so that they can all be done in one call.

```python
    system.tag.writeBlocking("[default]PressureTestV2/BatchStarted",0)
    system.tag.writeBlocking("[default]PressureTestV2/EndTime",system.date.now())

```

would become,

```python
    tagpaths = ["[default]PressureTestV2/BatchStarted", "[default]PressureTestV2/EndTime"]
    values = [0, system.date.now()]
    system.tag.writeBlocking(tagpaths, values)

```

I would bind the toggle switch to one boolean tag (make it a bidirectional tag binding) and enable history on that "onChange". Then get the tag history and write a script to loop through the returned data and convert it into start / end columns.

Modify your table's data binding. Make it 'Tall' and just the one tag (being written to by the toggle). Set the Value Format to 'Document' to return the data in JSON format.

Add a script transform and paste in the following code:

```python
def transform(self, value, quality, timestamp):
	output = []
	dic = {}
	for row in value:
		if row['running']:
			dic['startTime'] = row['t_stamp']
		else:
			dic['endTime'] = row['t_stamp']
			# Note that the tag history query results may start with an 'off' transition.
			# We'll ignore that if we see it. (It will depend on the start date.)
			if 'startTime' in dic: 
				output.append(dic)
			dic = {}
			
	return output

```

Change the table column field names to match (or edit the script). You already know how to format as datetime.

One of the Python guys will be along shortly to reduce my script to two lines!

---

<div class="post-metadata">

**Author:** ![sjjones](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sjjones](https://forum.inductiveautomation.com/u/sjjones)\
**Post date:** [August 12, 2025, 1:14pm UTC](https://forum.inductiveautomation.com/t/customizing-data-in-perspective-table-component/109599/5 "2025-08-12T13:14:00Z")

</div>

I had totally forgotten about transforms!!

I got it to work by doing a message handler. On a page start up I would send a message to a message handler on the table, and inside of the message handler I would do my data processing, which is much more convoluted.

Here’s the code (not my finest work, but it works)

```python
startPath = "[default]PressureTestV2/StartTime"
endPath = "[default]PressureTestV2/endTime"
startTime = system.date.addMonths(system.date.now(), -1)
endTime = system.date.now()

startResults = system.tag.queryTagHistory(
	paths=[startPath],
	startDate=startTime,
	endDate=endTime,
	returnSize=-1
)
endResults = system.tag.queryTagHistory(
	paths=[endPath],
	startDate=startTime,
	endDate=endTime,
	returnSize=-1
)

startValuesOnly = [startResults.getValueAt(row, 1) for row in range(startResults.rowCount)]
endValuesOnly = [endResults.getValueAt(row, 1) for row in range(endResults.rowCount)]

headers =["Start Time", "End Time"]

data = [[startValuesOnly[row],endValuesOnly[row]] for row in range(len(startValuesOnly))] 

startEndTimes = system.dataset.toDataSet(headers,data)

self.props.data = startEndTimes

col1 = self.props.columns[0]
col1.field = "Start Time"
col1.render = "date"
col1.dateFormat = "MM/DD/YYYY HH:mm:ss"

col2 = self.props.columns[1]
col2.field = "End Time"
col2.render = "date"
col2.dateFormat = "MM/DD/YYYY HH:mm:ss"

```

quite a bit of overhead, I know.

I’m definitely going to try your version as well. I’ll let you know how it goes!
