Conditionally change value of table cell

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.

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.

1 Like

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

Something like:

	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:

	if col == 1:
		if value == 1:
			return 'closed'
		elif value == 2:
			return 'opened'
	else:
		return defaultText
3 Likes

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’

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.

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

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

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

Thanks dude