# Table - Hide a column in perspective

**URL:** <https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316>\
**Category:** Ignition\
**Tags:** perspective, ignition80\
**Created:** [November 4, 2020, 10:28pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316 "2020-11-04T22:28:19Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [November 4, 2020, 10:28pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/1 "2020-11-04T22:28:19Z")

</div>

Hello 🙂

I’m trying to work on a table in perspective, and I have the data binded to a named query but I need some columns hidden. Is there a way to hide them in perspective? Thank you

---

<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:** [November 4, 2020, 10:38pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/2 "2020-11-04T22:38:47Z")

</div>

Use the `columns` property to do this.

1. Add a new column configuration for each column you want to display.
2. Set `props.columns[x].field` to the case-sensitive name of the column of data you want represented. If using a dataset, this value should be a case-sensitive match of the header of the DataSet column.

Using the default data in the table as an example, let’s say that I only want to display columns for “city” and “population” - I do NOT want to display “country” as a column.

Steps:

1. Add two column configurations, because I want two columns.
2. Set `props.columns[0].field` to have a value of “city”.
3. Set `props.columns[1].field` to have a value of “population”.  
 ![Screen Shot 2020-11-04 at 2.37.14PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/805c88a96d5c7ea61fd33c223f1fe8f27488cdc5.png)

---

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [November 4, 2020, 10:55pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/3 "2020-11-04T22:55:29Z")

</div>

You’re awesome. Thank you!

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 24, 2023, 9:41pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/4 "2023-05-24T21:41:01Z")

</div>

> 1. Add two column configurations, because I want two columns.

is there a way to add these columns using a script?  
i am asking because when i am displaying historic datasets from several tags the number of columns obviously will change.  
I need to add appropriate number of columns otherwise having just 1 column[0].field = 't\_stamp' will not allow the table to display the rest of the data.  
What i dont understand is how come when no columns configuration data was created the date time in epoch time was displayed along with the rest of the data ☹

---

<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 24, 2023, 9:54pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/5 "2023-05-24T21:54:23Z")

</div>

> [@hewking32](#):
>
> is there a way to add these columns using a script?

You can do anything in scripting, it just takes longer as you add more complications/requirements.

> [@hewking32](#):
>
> how come when no columns configuration data was created the date time in epoch time was displayed along with the rest of the data

Because that's how the date information is stored and returned. If you want it formatted, you need to specify a format string, which means you need to define a column for that information to live in.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [May 24, 2023, 9:57pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/6 "2023-05-24T21:57:59Z")

</div>

You could write a project script that you pass the table data into and it grabs the column names and generates the column configuration object for you. Generate the 't\_stamp' config first so it always sits on the left of the table. You then put the generated column configuration object in the table's `props.columns`.

Something like this should get you started on the script side. This script assumes you are passing a list of column names or the table data as a dataset.

```auto
def defaultTableColumnConfig():

	baseColumnConfig = {
		"align": "center",
		"boolean": "checkbox",
		"dateFormat": "MM/DD/YYYY",
		"editable": False,
		"field": "",
		"footer": {
			"align": "center",
			"justify": "left",
			"style": {
				"classes": ""
			},
			"title": ""
		},
		"header": {
			"align": "center",
			"justify": "left",
			"style": {
				"classes": ""
			},
			"title": ""
		},
		"justify": "auto",
		"number": "value",
		"numberFormat": "0,0.##",
		"progressBar": {
			"bar": {
				"color": "",
				"style": {
					"classes": ""
				}
			},
			"max": 100,
			"min": 0,
			"track": {
				"color": "",
				"style": {
					"classes": ""
				}
			},
			"value": {
				"enabled": True,
				"format": "0,0.##",
				"justify": "center",
				"style": {
					"classes": ""
				}
			}
		},
		"render": "auto",
		"resizable": True,
		"sort": "none",
		"sortable": True,
		"strictWidth": False,
		"style": {
			"classes": ""
		},
		"toggleSwitch": {
			"color": {
				"selected": "",
				"unselected": ""
			}
		},
		"viewParams": {},
		"viewPath": "",
		"visible": True,
		"width": ""
	}

	return baseColumnConfig

def generateWideTableColumnConfig(columnData, codes=None):

	if isinstance(columnData, list):
		columnNames = columnData
	else:
		columnNames = columnData.getColumnNames()

	columnConfig = []
	columnCount = 0

	for item in columnNames:
		tmpDict = defaultTableColumnConfig()
		if item == 't_stamp':
			tmpDict.update({
				"field": "t_stamp",
				"justify": "center",
				"style": {
					"paddingLeft": "5px",
					"paddingRight": "5px"
				},
				"sortable": True,
				"header": {
					"title": "Timestamp",
					"justify": "center"
				}
			})
		else:
			title = item
			if columnCount % 2:
				backgroundColor = ''
			else:
				backgroundColor = "#005EB833"

			tmpDict.update({
				"field": item,
				"justify": "center",
				"header": {"title": title, "justify": "left"},
				"sortable": False,
				"strictWidth": True,
				"width": 72,
				"style": {"wordBreak": "break-word", "backgroundColor": backgroundColor}
			})
			columnCount += 1

		columnConfig.append(tmpDict)

	return columnConfig

```

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 24, 2023, 10:33pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/7 "2023-05-24T22:33:21Z")

</div>

massive thanks

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 24, 2023, 10:35pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/8 "2023-05-24T22:35:08Z")

</div>

wow wow wow  
i pretty much copy pasted your code and ....it works  
i was sitting on this problem for the last several hours - thank you

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 24, 2023, 10:37pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/9 "2023-05-24T22:37:46Z")

</div>

@ryan.white i will have some beer now and analyze this code again tomorrow 🙂 - its 11pm at my place  
Your code did exactly what i needed but i wonder why after writing the config to the columns property the changes are not shown ? Trying to understand perspective bit by bit...  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/f/7fe08ced916a1267f58ac4f8dfefb30144e9bb9b.png)

---

<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:** [May 25, 2023, 7:06am UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/10 "2023-05-25T07:06:33Z")

</div>

How did you execute the code ?

For dynamic column configuration, I usually bind the columns property to the dataset, and use its headers to get the column names.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 25, 2023, 7:15am UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/11 "2023-05-25T07:15:10Z")

</div>

```auto
def runAction(self, event):
	SelectedTagList = self.getSibling("TagBrowseTree").props.selection.values
	endTime = system.date.now()
	startTime = system.date.addMinutes(endTime, -1)

	dataSet = system.tag.queryTagHistory(paths=SelectedTagList, startDate=startTime, endDate=endTime, returnSize=5, aggregationMode="Maximum", returnFormat='Wide')																																				

	self.parent.parent.getChild("Table").props.columns = Perspective.generateWideTableColumnConfig(dataSet)
	self.parent.parent.getChild("Table").props.data= dataSet

```

this is the code behind the button to add the history of the selected tags to the table,  
original dataset was then modified by the perspective.generateWideTableColumnConfig project function using the example from the previous post.  
The difficulty for me was to make the code work for any number of tags rather than fixed preselected number.

---

<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:** [May 25, 2023, 7:24am UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/12 "2023-05-25T07:24:25Z")

</div>

Considering this code should indeed add things to the columns property, I can think of several answers to 'why is there nothing in the columns property ?':

- The most obvious one: You tested the functionality, then checked the property outside of the test run.  
ie: you clicked the button in a browser, then checked the property in the designer.  
or you clicked in the designer's preview, then stopped it and checked the property after something cleared it.
- The code stopped executing because of an error (check the logs)
- The code worked but returned an empty list, because of a logic error.

---

<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:** [May 25, 2023, 7:32am UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/13 "2023-05-25T07:32:36Z")

</div>

I'd also like to add that you should probably move this to a binding on the columns property, instead of handling it on a button click.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 25, 2023, 7:33am UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/14 "2023-05-25T07:33:21Z")

</div>

yep you were right  
i closed perspective workstation and used only designer  
after running the code i deep selected different object and then deep selected the table  
the columns are shown now  
i feel better about my sanity now 🙂

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 25, 2023, 7:40am UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/15 "2023-05-25T07:40:06Z")

</div>

very interesting pointer but to be honest i dont know how to do it ☹  
how would it work in theory ? are binding preferred in general for some reason if possible?

at the moment button code takes selected tags from tree browse, queries the history of each tag,  
then calls the project function to modify the column to display the time in human readable format and then assigns modified dataset to the table.data property

When configuring the code in binding i am limited to the expression languagae only - (except runscript function which can be embedded in the expression and run either system function or project code)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [May 25, 2023, 6:21pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/16 "2023-05-25T18:21:45Z")

</div>

Bindings in perspective allow you to apply a script transform, which would allow you to write a normal python script.

An example binding would be to bind the columns property to the data property of the table, apply a script transform, and then call the function to generate the columns configuration.

> **Example Binding**
>
> ![exampleTableBinding](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/8/b84520e3ce58eb24ade978723b21b6c133c2cbb5.png)

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [May 25, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/table-hide-a-column-in-perspective/40316/17 "2023-05-25T18:52:32Z")

</div>

excellent example - thank you
