# Color Power Table configuration

**URL:** <https://forum.inductiveautomation.com/t/color-power-table-configuration/59919>\
**Category:** Ignition\
**Created:** [May 23, 2022, 5:44pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919 "2022-05-23T17:44:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [May 23, 2022, 5:44pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/1 "2022-05-23T17:44:58Z")

</div>

saludos! necesito su ayuda estoy tratando de dar color a las filas de mi tabla con las siguientes condiciones:1-rojo, si la fecha es anterior a la actual o ya caduco, 2-amarillo, si la fecha actual esta a punto de caducarse, 3-verde, si la fecha futura esta lejana a la actual… Gracias por su ayuda

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

---

<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:** [May 23, 2022, 5:50pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/2 "2022-05-23T17:50:10Z")

</div>

> [@](#):
>
> Cheers! I need your help I am trying to color the rows of my table with the following conditions: 1-red, if the date is before the current date or already expired, 2-yellow, if the current date is about to expire, 3 -green, if the future date is far from the current one… Thanks for your help

Is your expiration date in one of the power table columns? If so, what is the col name and what is the date format?

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [May 23, 2022, 5:53pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/3 "2022-05-23T17:53:44Z")

</div>

se encuentra en la columna “prox.mant” formato de fecha DD-MM-YYYY

---

<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:** [May 23, 2022, 6:16pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/4 "2022-05-23T18:16:39Z")

</div>

In the configureCell() extension function…

```auto
now = system.date.now()
expiration = system.date.parse(self.data.getValueAt(rowIndex, 'prox.mant'), 'DD-MM-YYYY')

// # if current date is greater than the expiration 
if now >= expiration:
	return {'background': 'red'}

// # if the current date is within 2 hours of expiration or whatever time frame you think is close
elif system.date.hoursBetween(now, expiration) <= 2: 
	return {'background': 'yellow'}

else:
	return {'background': 'green'}

```

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [May 23, 2022, 6:47pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/5 "2022-05-23T18:47:10Z")

</div>

tengo este problema probablemente no estaré haciéndolo correctamente

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

---

<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:** [May 23, 2022, 6:49pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/6 "2022-05-23T18:49:49Z")

</div>

Looks like your first two lines are not indented (tab) . it should look like this

```auto
def configureCell(self, value, textValue, selected, rowIndex, colIndex, colName, rowView, colView):
	"""
	Provides a chance to configure the contents of each cell. Return a
	dictionary of name-value pairs with the desired attributes. Available
	attributes include: 'background', 'border', 'font', 'foreground',
	'horizontalAlignment', 'iconPath', 'text', 'toolTipText',
	'verticalAlignment'

You may also specify the attribute 'renderer', which is expected to be a
	javax.swing.JComponent which will be used to render the cell.

	Arguments:
		self: A reference to the component that is invoking this function.
		value: The value in the dataset at this cell
		textValue: The text the table expects to display at this cell (may be
		           overridden by including 'text' attribute in returned dictionary)
		selected: A boolean indicating whether this cell is currently selected
		rowIndex: The index of the row in the underlying dataset
		colIndex: The index of the column in the underlying dataset
		colName: The name of the column in the underlying dataset
		rowView: The index of the row, as it appears in the table view
		         (affected by sorting)
		colView: The index of the column, as it appears in the table view
		         (affected by column re-arranging and hiding)
	"""
	now = system.date.now()
	expiration = system.date.parse(self.data.getValueAt(rowIndex, 'prox.mant'), 'DD-MM-YYYY')
	
	# if current date is greater than the expiration 
	if now >= expiration:
		return {'background': 'red'}
	
	# if the current date is within 2 hours of expiration or whatever time frame you think is close
	elif system.date.hoursBetween(now, expiration) <= 2: 
		return {'background': 'yellow'}
	
	else:
		return {'background': 'green'}
```

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [May 24, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/7 "2022-05-24T16:14:20Z")

</div>

realice la prueba con el código, pero obtuve errores inesperados por lo cual tuve que definirlo como función y todo parece estar bien (hasta que) obtuve el siguiente error:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/8/38226447c68289614e53868f9599ee46f508069e.png)

---

<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:** [May 24, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/8 "2022-05-24T17:18:11Z")

</div>

post your script and format it with the preformatted text button that looks like `</>`

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [May 24, 2022, 5:21pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/9 "2022-05-24T17:21:40Z")

</div>

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

este es el código con ciertas modificaciones

---

<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:** [May 24, 2022, 5:29pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/10 "2022-05-24T17:29:52Z")

</div>

I tried your script on my table and it works fine. Try deleting the whitespace tabs/spaces and indent the code again with tabs to see if there is something wrong with the whitespace.

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [May 30, 2022, 2:35pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/11 "2022-05-30T14:35:51Z")

</div>

saludos, eh estado intentando esto durante días pero aun no tengo ningún avance, me di cuenta que tenia campos vacíos en la fecha así que los complete pero no funciono, ahora me di cuenta que las fechas están repetidas pero no las puedo cambiar porque son necesarias

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/a/8a03efd3fc8b96a1fa2ebd8c1b258c4135ae5544.png)  
será que este es MI ERROR ?  
una vez aplico el script la tabla se me ralentiza será normal

---

<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:** [May 30, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/12 "2022-05-30T15:16:22Z")

</div>

Your date string format is wrong for what you have in your table, IE `15/ago/2021` does not match the parsing pattern of `DD-MM-YYYY`.

[https://docs.inductiveautomation.com/display/DOC81/Data+Type+Formatting+Reference](https://docs.inductiveautomation.com/display/DOC81/Data+Type+Formatting+Reference)

Try changing that portion to

```auto
expira = system.date.parse(self.data.getValueAt(rowIndex, 'prox.mant'), 'dd/MMM/yyyy')

```

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [June 1, 2022, 2:05pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/13 "2022-06-01T14:05:52Z")

</div>

lo hice tome en cuenta que también hay hora y minutos, lo hice de esta manera pero no funciona

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/6449a9978cc66baf906fdea069abe34fee85ce08.png)  
no entiendo porque no funciona en esta power table cuando en otras si funciona, ay algun problema si tengo habilitado el onCellEdited ?

---

<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:** [June 1, 2022, 2:31pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/14 "2022-06-01T14:31:43Z")

</div>

I just tested it, and it works for me.

1. add power table
2. add data (NOMBRE is string column, Prox. Mant. is string column)
3. add configureCell Script

```auto
now = system.date.now()
exp = system.date.parse(self.data.getValueAt(rowIndex, 'Prox. Mant.'), 'dd/MMM/yyyy')
# if current date is greater than the expiration 
if now >= exp:
	return {'background': 'red'}
	
# if the current date is within 5 months of expiration
elif system.date.monthsBetween(now, exp) <= 5: 
	return {'background': 'yellow'}
	
else:
	return {'background': 'green'}

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17c87182a99fc8daafbb3459cff72ab36a838969.png)

If `Prox. Mant.` is already a date type column and not a string, then you don’t need `system.date.parse` just the `getValueAt` part

```auto
now = system.date.now()
exp = self.data.getValueAt(rowIndex, 'Prox. Mant.')
# if current date is greater than the expiration 
if now >= exp:
	return {'background': 'red'}
	
# if the current date is within 5 months of expiration
elif system.date.monthsBetween(now, exp) <= 5: 
	return {'background': 'yellow'}
	
else:
	return {'background': 'green'}

```

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

---

<div class="post-metadata">

**Author:** ![JHON\_FLOREZ](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@JHON\_FLOREZ](https://forum.inductiveautomation.com/u/JHON_FLOREZ)\
**Post date:** [June 6, 2022, 8:23pm UTC](https://forum.inductiveautomation.com/t/color-power-table-configuration/59919/15 "2022-06-06T20:23:09Z")

</div>

GRACIAS por tu ayuda 👍🏻 👍🏻
