what is the property just for the text color?
color
I thought that when I saw the text properties but in practice it is not possible, just change that property for the _id
Status=row.C15
if Status=="NO ANSWER" and row['Origen']== "Externo" :
row['_id']= {'value': row['_id'], 'style': {'Color': '#FFCCCC'}}
row['Origen']= {'value': row['Origen'], 'style': {'backgroundColor': '#FFCCCC'}}
row['Destino']= {'value': row['Destino'], 'style': {'backgroundColor': '#FFCCCC'}}
row['C10']= {'value': row['C10'], 'style': {'backgroundColor': '#FFCCCC'}}
row['C14']= {'value': row['C14'], 'style': {'backgroundColor': '#FFCCCC'}}
row['C15']= {'value': Status, 'style': {'backgroundColor': '#FFCCCC'}}
row['C17']= {'value': row['C17'], 'style': {'backgroundColor': '#FFCCCC'}}
row['file']= {'value': row['file'], 'style': {'backgroundColor': '#FFCCCC'}}
OutputJson.append(row)
return OutputJson
it´s working now. is sensitive to Upercase
Perfect! That is exactly what I was looking for!
Hello, Could you please help me idetify where should I use the code?
I have a table from a SQL query in Dataset form.
Go watch this video: Cell color related to content in Ignition Perspective - #8 by danieltalbot
Welcome to the forum, Ivan.
For anyone to test or correct your code they would have to type it all out again. Please see Wiki - how to post code on this forum.
Also, if you hover over the Error_ScriptEval message at the bottom of the dialog it will give you a good clue to the nature of the problem. Be sure to include the error details when seeking help.
A few things:
- first take a few basic python courses, or read some tutorials. It might seem boring now, but you need to invest that time to be more efficient and not rely on forums for the most simple errors in the future
- Indent everything properly:
The whole thing is indented with 2 tabs, which is not a problem in itself as long as the indentation is consistent. But I suggest you take it back to one tab only.
now, notice how theif
andelse
are not on the same indentation level ? That's an issue. Scope is based on indentation in python, so here yourif
andelse
are NOT related. Which means you have anelse
without anif
. And that's an error - You're returning in the loop. While not an error it itself, it really is NOT what you want to be doing here.
- It seems you're applying the same style to every cell in the row. You can apply style to the row directly, it will make things much simpler to write, read, and maintain. It might also be more efficient.
- The whole point of a default is that you don't need to do anything. You don't need to apply nothing to get the default style. Actually, you might even be overriding it with nothing (I think it's not the case here, but the point still stands).
So, I'd suggest changing the return type of the query binding to json
, and then you can do this:
acked_style = {'backgroundColor': "#00ff00"}
output = []
for row in value:
r = {'value': row}
if row['ACK_BY'] == "":
r['style'] = acked_style
output.append(r)
return output
Or, you can do this:
acked_style = {'backgroundColor': "#00ff00"}
headers = value.columnNames
data = [{'value': dict(zip(headers, row))} for row in system.dataset.toPyDataSet(value)]
for row in data:
if row['value']['ACK_BY'] == "":
row['style'] = acked_style
return data
last edit: just for fun:
return [dict(row, **({'style':{'backgroundColor': "#00ff00"}} if row['value']['ACK_BY'] else {})) for row in ({'value': dict(zip(value.columnNames, row))} for row in system.dataset.toPyDataSet(value))]
yes I did make it more complicated than it actually needs to be...but that's part of the fun.
Hi
I am trying to implement same features to my table and I am getting an output as
Can anyone guide me what is going wrong, as with this output Table row color is not changing.
Thanks
Your style
object is OK.
You just need to move everything else into a value
object.
Tip: start using the Built-in Theme Colors.