# Customizing Perspective Table and json scripting help

**URL:** <https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 27, 2022, 1:30pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348 "2022-07-27T13:30:56Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 24, 2022, 7:28pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/41 "2022-08-24T19:28:52Z")

</div>

Thanks

The asterisks are pretty new to me in Python.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 24, 2022, 7:42pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/42 "2022-08-24T19:42:50Z")

</div>

Look up packing and unpacking regarding python to understand the asteriks in python. Usually are used to unpack/pack dictionaries/lists/tuples. Very helpful shortcut when you get the hang of it.

Decent enough article on it [Packing and Unpacking Arguments in Python - GeeksforGeeks](https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 25, 2022, 9:01pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/43 "2022-08-25T21:01:29Z")

</div>

```auto
baseStyle = {
			'fontSize': 36,
			'fontWeight': 500,
			'borderStyle': 'ridge' 
		}
subStyle= dict(backgroundColor= '#FF3131', **baseStyle)

```

This didn’t work.  
I am not sure, but I think it is the format.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 25, 2022, 9:32pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/44 "2022-08-25T21:32:31Z")

</div>

Formatting isn’t an issue (for me anyway).

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

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 26, 2022, 1:49pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/45 "2022-08-26T13:49:29Z")

</div>

Was it the tick marks on green that made the difference?

`subStyle= dict(backgroundColor= '#FF3131', **baseStyle)`  
This didn’t work. Does that mean it was the tick marks or is the return different than the variable being returned?

---

<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:** [August 26, 2022, 2:25pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/46 "2022-08-26T14:25:28Z")

</div>

You’re not showing your actual code, but it’s different from anything I’ve posted, because I don’t have a `subStyle` variable. Without showing the actual full code, it’s impossible to determine what’s going wrong.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 26, 2022, 3:22pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/47 "2022-08-26T15:22:15Z")

</div>

Thanks for helping.  
I will try it again on Monday.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2022, 3:14pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/48 "2022-09-22T15:14:52Z")

</div>

Edit: I had a container set the wrong size, got my table to be smaller now.  
After testing a bit though, `, 'minHeight':600` did change the result.

Not sure how to implement the base style concept still.

```auto
def getStyle(row, col):
			baseStyle = {	'fontSize': 30,	'fontWeight': 500,	'borderStyle': 'ridge' , 'minHeight':30 }
			if value.getValueAt(row,"Running")==0 and value.getValueAt(row,"StateDuration")>=5 and value.getValueAt(row,"Infeed")>1000 and value.getValueAt(row,"Outfeed")>1000:
				subStyle= {'fontSize': 30,'fontWeight': 500,'backgroundColor': '#FF3131', 'borderStyle':'ridge', 'minHeight':30 }
			elif row%2==0 :
				subStyle= {'fontSize': 30,'fontWeight': 500,'backgroundColor': '#ffffff', 'borderStyle':'ridge', 'minHeight':30}
			elif row%2!=0 :
				subStyle= {'fontSize': 30,'fontWeight': 500,'backgroundColor': '#a0bed8', 'borderStyle':'ridge', 'minHeight':30}
		
							
			return subStyle

	value = [{value.getColumnName(col):{'value': value.getValueAt(row,col), 'style': getStyle(row, col) } for col in range(value.getColumnCount())} for row in range(value.getRowCount())]

	return value	

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 22, 2022, 5:21pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/49 "2022-09-22T17:21:42Z")

</div>

You would implement it like this:

```python
def getStyle(row, col):
	baseStyle = {'fontSize': 30,'fontWeight': 500,'borderStyle': 'ridge' ,'minHeight':30}
	if value.getValueAt(row,"Running")==0 and value.getValueAt(row,"StateDuration")>=5 and value.getValueAt(row,"Infeed")>1000 and value.getValueAt(row,"Outfeed")>1000:
		return dict(backgroundColor = '#FF3131', **baseStyle)
	elif row % 2:
		return dict(backgroundColor = '#ffffff', **baseStyle)
	else:
		return dict(backgroundColor = '#a0bed8', **baseStyle)

	value = [{value.getColumnName(col):{'value': value.getValueAt(row,col), 'style': getStyle(row, col) } for col in range(value.getColumnCount())} for row in range(value.getRowCount())]

	return value

```

At the very least, don’t define baseStyle and then never use it, you could also do this:

```python
def getStyle(row, col):
	baseStyle = {'fontSize': 30,'fontWeight': 500,'borderStyle': 'ridge' ,'minHeight':30}
	if value.getValueAt(row,"Running")==0 and value.getValueAt(row,"StateDuration")>=5 and value.getValueAt(row,"Infeed")>1000 and value.getValueAt(row,"Outfeed")>1000:
		baseStyle['backgroundColor'] = '#FF3131'
	elif row%2:
		baseStyle['backgroundColor'] = '#ffffff'
	else:
		baseStyle['backgroundColor'] = '#a0bed8'

	return baseStyle

	value = [{value.getColumnName(col):{'value': value.getValueAt(row,col), 'style': getStyle(row, col) } for col in range(value.getColumnCount())} for row in range(value.getRowCount())]

	return value	

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2022, 7:06pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/50 "2022-09-22T19:06:07Z")

</div>

Thanks

I didn’t know it was possible to set new values and keys with :  
`dictionaryName[key]=value`  
If I understood that correctly.

* * *

I am struggling a bit trying to append a totals column.

```auto
Scrap='0.0%'
# Scrap=sum(value.getValueAt(row,value.getColumnIndex('Scrap') for row in range(value.getRowCount()))
Total= {'Line':{'value':'Total','style':baseStyle} , 
	    'Scrap':{'value':Scrap,'style':baseStyle} }
value.append(Total)

```

I got this to sort of work.  
The commented out line though, it doesn’t work and I am not sure why.

This page uses double quote instead of single, is that right?  
[https://docs.inductiveautomation.com/display/DOC81/Datasets#Datasets-AccessingDatainaDataset](https://docs.inductiveautomation.com/display/DOC81/Datasets#Datasets-AccessingDatainaDataset)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 22, 2022, 7:14pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/51 "2022-09-22T19:14:36Z")

</div>

> [@zacharyw.larson](#):
>
> The commented out line though, it doesn’t work and I am not sure why

At first glance it looks alright, what error/unexpected result is it giving you?

> [@zacharyw.larson](#):
>
> This page uses double quote instead of single, is that right?

Python is quote agnostic, it doesn't care if you use single or double quotes, so long as they match.

```python
print "This string will 'allow' single qoutes because they are contianed by double quotes"
print 'This string will "allow" double qoutes because they are contined by single quotes'
print 'Though you can use \'escape\' characters if you really want to'

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2022, 7:15pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/52 "2022-09-22T19:15:56Z")

</div>

Thanks

I was calling dataset functions on the list I had created to return the json.  
Fixed that.

Now I named that list value2, and I append to value2.  
Also, I had too many parenthesis.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [October 3, 2022, 8:15pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/53 "2022-10-03T20:15:58Z")

</div>

Two questions:

 
 1.  

~~Is there a way to change the value in the dataset with the if statements in that def style function?~~

2. Can I change the border of a row without impacting the vertical lines between cells?

* * *

Thanks LRose!  
Removed the non-sense code I had in this spot.

* * *

I think I can edit the colors of each side of a cell independently, but it looks messy to set the row border to highlight.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 3, 2022, 8:41pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/54 "2022-10-03T20:41:45Z")

</div>

You're looking for `system.dataset.setValue()`, which because datasets are immutable (this is why there are not `set*` functions on the dataset object) returns a new dataset object with the value at the specified location set to the provided value.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 23, 2023, 12:54pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/55 "2023-03-23T12:54:12Z")

</div>

**Is it possible to make the table look like labels on a flat color?**  
**No border, no cells, not look like a table at all?**

I have 3 labels with separate bindings right now, and then three other labels as headers.  
My thought is that if I can conceal that I am using a table, I can use a single binding on the component.

* * *

It will eliminate some bindings for me.  
It will reduce some work for me.  
It will eliminate this issue I have where if I bind to another object, and then property reference then when the page loads for a very small amount of time the page appears to have an error on load.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 23, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/56 "2023-03-23T13:11:10Z")

</div>

Worst case scenario you can hide everything with css...

edit:

Well, if you disable the header and pager, disable the stripes, add 'borderStyle: none' to the table styles...  
Isn't that what you want ?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 23, 2023, 1:12pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/57 "2023-03-23T13:12:55Z")

</div>

> [@zacharyw.larson](#):
>
> I have 3 labels with separate bindings right now, and then three other labels as headers.  
> My thought is that if I can conceal that I am using a table, I can use a single binding on the component.

Meh, I would create a custom property and with you data binding, and then use an expression binding on each label to that with and expression binding using the `lookup()` expression.

Don't overcomplicate things for the sake of optimization.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 23, 2023, 1:17pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/58 "2023-03-23T13:17:47Z")

</div>

Premature optimization is the root of all evil

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 23, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/59 "2023-03-23T13:19:15Z")

</div>

I don't think it is premature optimization.  
The page has existed for a long time.  
When do you think is a good time for optimization?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 23, 2023, 1:24pm UTC](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348/60 "2023-03-23T13:24:57Z")

</div>

I mean try to use best practices when I initially design a page, but I have plenty of old projects I have to occasionally maintain or update that have plenty of non-ideal setups, but only when someone complains "hey this thing is really slow" will I try to optimize. However many of the non-ideal setups work well enough that I never hear that.

I would say its appropriate to optimize when 1) there is a noticeable performance issue that users notice and 2) you know that it's an issue with your design of the page and not something else (network latency, a slow db, etc). There is plenty to cause bad performance in a vision/perpective application before you ever look at the designer. Not to say bad design can't be the cause, god knows I've made accidental infinite property change loops that crashed my vision application before lol. But it's good to check all your bases and try to figure out what is the main cause of the slowness so your optimization can be pointed at the right thing. You could very well optimize this page and still have performance issues because that was not the problem for instance.

[Previous page](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348.md?page=2)

[Next page](https://forum.inductiveautomation.com/t/customizing-perspective-table-and-json-scripting-help/62348.md?page=4)
