# Conditionally change value of table cell

**URL:** <https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076>\
**Category:** General Discussion\
**Created:** [October 14, 2019, 7:00pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076 "2019-10-14T19:00:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [October 14, 2019, 7:00pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076/1 "2019-10-14T19:00:59Z")

</div>

Hi

I history a tag which has two values; 1 for close state and 2 for open state and I want to show it on table with ‘open’ and ‘close’ string instead of 1 & 2.  
what is the easiest way to do that? I’m looking for method like row versioning so I can conditionally change the cell value instead of its color cell.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 14, 2019, 7:06pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076/2 "2019-10-14T19:06:48Z")

</div>

I haven’t done much with querying tag history, but I do the same thing with machine state on our CNCs from a regular db table. Their tag state is 0-4, but I display them as run, stop, pause, reset, and manual by using a join query. You have a separate table that has the alias name for each state. Then you can join the query to that table using the alias and not the state.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [October 14, 2019, 8:06pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076/3 "2019-10-14T20:06:20Z")

</div>

If your using a power table, you can do a simple script in the configureCell extention function.

Something like:

```auto
	if colName == 'your column name':
		if value == 1:
			return {'text': 'closed'}
		elif value == 2:
			return {'text': 'opened'}

```

With a regular table you can do it to in the getDisplayTextAt extension function using something like:

```auto
	if col == 1:
		if value == 1:
			return 'closed'
		elif value == 2:
			return 'opened'
	else:
		return defaultText

```

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [October 17, 2019, 1:05pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076/4 "2019-10-17T13:05:41Z")

</div>

Hi Bpreston  
Thanks for the solution. By the way if i want to set a cell text base on itself and another cell at same time how can i do that in getDisplayTextAt?  
for example I have two column like this:  
Command code  
0 2  
1 1  
if command is 1 and code is 2 show ‘close’ and if command is 1 and code is 1 show ‘open’

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [October 17, 2019, 1:36pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076/5 "2019-10-17T13:36:10Z")

</div>

You can pull your dataset into your script and extract values from the columns you want using the row value then return what you create as the result. To pull the data out it would be like what I have below. Then you would just need to use if statements with these values to decide the value return.

```auto
data = self.data
val1 = data.getValueAt(row,0)
val2 = data.getValueAt(row,1)

```

For the if statement with your example, it would be:

```auto
if val1 == 1 and val2 == 2:
     return 'close'
elif val1 ==1 and val2 == 1:
     return 'open'

```

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [October 17, 2019, 2:05pm UTC](https://forum.inductiveautomation.com/t/conditionally-change-value-of-table-cell/29076/6 "2019-10-17T14:05:04Z")

</div>

> [@bpreston](#):
>
> data = self.data val1 = data.getValueAt(row,0) val2 = data.getValueAt(row,1)

Thanks dude
