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
Is your expiration date in one of the power table columns? If so, what is the col name and what is the date format?
se encuentra en la columna “prox.mant” formato de fecha DD-MM-YYYY
In the configureCell() extension function…
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'}
Looks like your first two lines are not indented (tab) . it should look like this
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'}
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:
post your script and format it with the preformatted text button that looks like </>
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.
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
será que este es MI ERROR ?
una vez aplico el script la tabla se me ralentiza será normal
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
Try changing that portion to
expira = system.date.parse(self.data.getValueAt(rowIndex, 'prox.mant'), 'dd/MMM/yyyy')
lo hice tome en cuenta que también hay hora y minutos, lo hice de esta manera pero no funciona
no entiendo porque no funciona en esta power table cuando en otras si funciona, ay algun problema si tengo habilitado el onCellEdited ?
I just tested it, and it works for me.
- add power table
- add data (NOMBRE is string column, Prox. Mant. is string column)
- add configureCell Script
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'}
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
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'}
GRACIAS por tu ayuda