Jump to content

Creating Available Stock traffic lights - Color Formatting text AND text background Based on Cell Value in a table


Recommended Posts

In the column STOCK, I have a Calculated field that sometimes shows numbers or is blank, in those cases I don't need to format the value.

But when the Value is A B or C I need to color the text AND the background of the text
A: red / B: yellow / C : green

 

 

image.thumb.png.56862be48672ed4dcdc6bf3daba1a845.png

Link to comment
Share on other sites

You can achieve this by doing the following:

Remove your STOCK field and add an HTML block that will act as the Stock column. Label the HTML Block as "STOCK".

Disable HTML editor in the HTML block advanced options tab.

Copy and paste the code below into the HTML block:

Replace the 7 instances of FIELDNAME below with the name of your STOCK Field.

You can adjust the color, background color, and padding in each statement below as needed.

 

<div id="mydiv[@field:ID]"> </div>

<SCRIPT LANGUAGE="JavaScript">

if ("[@field:FIELDNAME]" == "A") {
document.getElementById("mydiv[@field:ID]").innerHTML ="<span style='color:white;background-color:red;padding:6px;'> [@field:FIELDNAME]</span>";

else if ("[@field:FIELDNAME]" == "B") {
document.getElementById("mydiv[@field:ID]").innerHTML ="<span style='color:black;background-color:yellow;padding:6px;'> [@field:FIELDNAME]</span>";

else if ("[@field:FIELDNAME]" == "C") {
document.getElementById("mydiv[@field:ID]").innerHTML ="<span style='color:white;background-color:green;padding:6px;'> [@field:FIELDNAME]</span>";

} else{
document.getElementById("mydiv[@field:ID]").innerHTML ="[@field:FIELDNAME]";

}

</SCRIPT>

 

See this article for more info:

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...