# Table header missing when named query is not returning any data

**URL:** <https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 10, 2025, 3:57pm UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461 "2025-03-10T15:57:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Tornblom](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Thomas\_Tornblom](https://forum.inductiveautomation.com/u/Thomas_Tornblom)\
**Post date:** [March 10, 2025, 3:57pm UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/1 "2025-03-10T15:57:03Z")

</div>

Hi, I have a problem with a table in perspective.  
The table header is missing when the named query is not returning any data.  
I have a script transform that requires the data to be in json format that can make this problem more difficult to solve, I have seen solutions for data in dataset format but I can't use this here.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 10, 2025, 4:39pm UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/2 "2025-03-10T16:39:47Z")

</div>

> [@Thomas\_Tornblom](#):
>
> I have a script transform that requires the data to be in json format

Share this. (A script that handles datasets is very similar to a script that handles json.)

You can also do your NQ binding in a custom property, returning a dataset (so you have access to ordered column names and types), and then transforming to the table's required JSON separately.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tornblom](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Thomas\_Tornblom](https://forum.inductiveautomation.com/u/Thomas_Tornblom)\
**Post date:** [March 11, 2025, 6:39am UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/3 "2025-03-11T06:39:28Z")

</div>

Hi,

This is the transformation script I use, it's used to change the colors on status.

```python
def transform(self, value, quality, timestamp):
	style_green = {"backgroundColor": "#33FF57"}
	style_red = {"backgroundColor": "#FF3300", "color": "#FFFFFF"}
	style_yellow = {"backgroundColor": "#FFFF00"}
	style_white = {"backgroundColor": "#FFFFFF"}
	newData = []
	#iterate over each row in 'value', which is the original result set
	for row in value:
		#Within the row, iterate over each column
		for col in row:
				#Create a variable to store the contents of the original *cell'
				cell = row [col]
				if col == "STATUS":
					if cell == "New":
						for col in row:
							cell = row[col]
							row[col] = {"value": cell, "style": style_yellow}
					elif cell == "Active":
						for col in row:
							cell = row[col]
							row[col] = {"value": cell, "style": style_green}
					elif cell == "Failed":
						for col in row:
							cell = row[col]
							row[col] = {"value": cell, "style": style_red}
					else:
						row[col] = {"value": cell, "style":style_white}	
		#Add the modified row to the list we initialzed earlier
		newData.append(row)
	return newData

```

```python
type or paste code here

```

---

<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 11, 2025, 8:46am UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/4 "2025-03-11T08:46:21Z")

</div>

You can't use a dataset if you're modifying styles anyway.  
But let's make this script a bit simpler !

This should do the same thing, with one exception: The style is applied to the row, not the cells. But you're applying the same style to each cell, so it should look the same.

```python
def transform(self, value, quality, timestamp):
	styles = {
		'new': {"backgroundColor": "#FFFF00"},
		'active': {"backgroundColor": "#33FF57"},
		'failed': {"backgroundColor": "#FF3300", "color": "#FFFFFF"},
		'default': {"backgroundColor": "#FFFFFF"}
	}
	return [
		{
			'value': row,
			'style': styles.get(row['STATUS'].lower(), styles['default'])
		} for row in value
	]

```

If you want to still display the headers when there's no data, you'll have to return an empty row, with the proper headers. For example, with the sample data that comes with a table (+ a 'STATUS' column):

```python
def transform(self, value, quality, timestamp):
	if value:
		styles = {
			'new': {"backgroundColor": "#FFFF00"},
			'active': {"backgroundColor": "#33FF57"},
			'failed': {"backgroundColor": "#FF3300", "color": "#FFFFFF"},
			'default': {"backgroundColor": "#FFFFFF"}
		}
		return [
			{
				'value': row,
				'style': styles.get(row['STATUS'].lower(), styles['default'])
			} for row in value
		]
	else:
		return [
			{
				'country': None,
				'city': None,
				'population': None,
				'STATUS': None
			}
		]

```

But there's a property to display a message when there's no data:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9d41ebc16ebdd3d606cb10a066339dba47877bc3.png)  
Do you really need column headers when the table is empty, or would a message be enough ?

---

<div class="post-metadata">

**Author:** ![Thomas\_Tornblom](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Thomas\_Tornblom](https://forum.inductiveautomation.com/u/Thomas_Tornblom)\
**Post date:** [March 11, 2025, 9:24am UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/5 "2025-03-11T09:24:19Z")

</div>

Thanks,

I already use the emptyMessage option and it's working fine.  
What I don't want is the blank space where the header is supposed to be.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/2/427325f9aa05e58a130f84c110490dc6d617332b.png)

---

<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:** [March 11, 2025, 9:40am UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/6 "2025-03-11T09:40:14Z")

</div>

Create an expression binding on `enableHeader` to only show when there is data. Something like,

```python
!isNull({this.props.data})
&&
{this.props.data} != ""

```

(I don't know what `data` will look like in your situation.)

---

<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 11, 2025, 10:03am UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/7 "2025-03-11T10:03:09Z")

</div>

Data will most likely be an empty list, so I'd suggest `len({this.props.data}) > 0`, which would also work for an empty string anyway.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tornblom](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Thomas\_Tornblom](https://forum.inductiveautomation.com/u/Thomas_Tornblom)\
**Post date:** [March 11, 2025, 12:50pm UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/8 "2025-03-11T12:50:58Z")

</div>

Thanks @pascal.fragnoud and @Transistor  
That solved the problem.

---

<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:** [March 11, 2025, 12:54pm UTC](https://forum.inductiveautomation.com/t/table-header-missing-when-named-query-is-not-returning-any-data/103461/9 "2025-03-11T12:54:00Z")

</div>

Good. Hit the **Solution** button on one or other answer to mark it solved. It then shows up as solved in the main index and a summary of the solution shows up under your original post. (I don't mind which.)
