Can I color the rows alternating as well as highlight a cell based on the value in it?
I was able to alternate the rows by writing the code in the initialize function or i can color the cell by writing something in the configureCell but I am not able to do both. Can anyone shed some light on how I can achieve this?
If the colour needs to change during runtime, you will have to do everything in the configureCell function.
You can set a default colour based on the row number, and make it alternating that way (different colour for even and odd rows). And then override the colour for the cells that have the “selected” flag set.
I tried that but it does not seem to have the effect i like.
By default i want alternating rows colored. I am able to do this by have the code in initialize function.
I also want the individual cell colored based on the value so I have the code to check the value in configureCell function; as soon as I do that the alternating row coloring is lost. Looks like I can either have the rows colored or the cell colored but not both.
If i did like what you suggested then I end up with only alternate row coloring. But i would like to add cell coloring in addition to that something like the attached picture
The way I do it is to build a dictionary of attributes, starting with the formatting of least precedence. Then I add or ‘override’ attributes with additional logic as needed.
attributes = {"background": "#FFFFFF", "foreground": "#000000"}
if rowIndex % 2 == 0:
attributes["background"] = "#EEECE8"
if colName == "val":
if self.data.getValueAt(rowIndex, "writeable") == True:
attributes["background"] = "#FFFF47"
if colName == "alarm" and value is not None:
attributes["text"] = None
elif colName == "unit" and value is None:
attributes["text"] = None
if self.data.getValueAt(rowIndex, "alarm") is not None:
attributes["iconPath"] = "CustomIcons/Indicator_Red.png"
if value < 1:
attributes["iconPath"] = "CustomIcons/Indicator_Green.png"
return attributes
I am trying to highlight a complete row white, yellow or green based on a value in a column(10) in the cell. It is a number 0 to 100 where 0 would be white, 100 would be green and yellow is 0 thru 100.
Thought I could use something like this(self.data.getValueAt(rowIndex ,10) but the variations of code I could only get the column 10 to work. I don’t know how to apply the color for the whole row based on 1 column’s value of that row.
It sounds like you are only having the script run for that column. Take out any conditional that filters on that column.
The example I posted is built to format differently for cells in each column. I you want every cell in each row to be highlighted then you don;t need to check the colName variable.
My understanding is that each cell is examined for its cell formatting. I am not sure how to apply code for each cell in a row to look at another cells value and then apply the color. Any help would be appreciated.
Hi,
I’ve errors when I use rowIndex:
…expecting INDENT…
Afer so much time searching for an typping error I tried the code only changing:
rowIndex for rowView.
Then it works for me.
That suggests a Python indentation error. Pay attention to consistent indentation and use tabs.
If pasting code here then use the </> code formatting button to format your code correctly and apply syntax highlighting.
@srinivas_anupurapu - You're asking in a thread that has been more than a year since the last post so it's unlikely that the original posters will notice this. I happened to stumble on to this, so I will show you an example I have done.
This configures a power table with alternating light yellow and light green rows by default. If a cell contains a NULL value, then that cell is gray (without changing the rest of the row). If a cell contains a date too far in the future, the cell is light blue. If the cell contains a date whose hour is set to 12 then that cell is red.