0

Intent: For a color to display on the entire line item according to another column result.

Problem: I want to accomplish using calculated column. I was able to create to the code below but it only shows per column result. I found this very helpful page Column Color Code, but they are not using calculated column.

Can someone look at the calculated code to tell me whats wrong and why it's not showing across the entire line item?

=CONCATENATE(
    "<DIV"
    ,IF([Status]="1"
        ," style='background-color:green;color:white;'"
            ,IF([Status]="2",
                " style='background-color:yellow;'"
                    ,IF([Status]="3"
                        ," style='background-color:red;color:white;'"
                        ,IF([Status]="4"
                            ," style='background-color:purple;color:white;'"
                            ,""
                        )
                    )
                )
            ,">"
        ,Title
    ,"</DIV>"
    )
  • 2
    Since calculated column is just another column in the list, you cannot change the entire row with it.. You should use the approach from the page you found. – Damjan Tomic Feb 2 '17 at 23:02
2

As said in the comments, the Calculated Column is displayed IN the cell, so you can only display content IN that cell

Your Formula is also incorrect, missing a )
You now stick your HTML IN the first IF

=CONCATENATE( 
  "<DIV"
  ,IF( [Status]="1"
           ," style='background-color:green;color:white;'"
           ,IF( [Status]="2",
                " style='background-color:yellow;'"
                , IF([Status]="3"
                     ," style='background-color:red;color:white;'"
                     , IF([Status]="4"
                          ," style='background-color:purple;color:white;'"
                          ,""
                         )
                    )
              )
           ,">"
           ,Title
           ,"</DIV>"
         )

JavaScript in a Calculated Column Formula

To target the whole TR Table Row you have to use JavaScript
to get out of that Table Cell and "Walk up the Browser DOM",

=[Status]
 &"<img src=""/_layouts/images/blank.gif"" onload=""{"
     &"var row=this;while(row.tagName!='TR'){row=row.parentNode}"
     &"row.style.backgroundColor='"
        &CHOOSE( [Status] , "green" , "yellow" , "red" , "purple" )
        &"';"
     &"row.style.color='"
        &CHOOSE( [Status] , "white" , "black" , "white" , "white" )
        &"';"
 &"'}"">"

Disclaimer I did not test this Formula with your data

Full explanation & building it step by step is at: http://www.viewmaster365.com/#/How

Be sure to read all the Pros and Cons, there are a few snags sticking HTML in a Formula

The CSR (Client Side Rendering) example you referred to might suit better

When you are going the CSR Route, use the (best thing since sliced bread)
Cisar Chrome Extension Andrei Markeev wrote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.