Jump to content

Background color of calculated fields


Recommended Posts

I have some code that changes the background of a cell in the PRR column conditional on the value it contains:

image.png.0cd9d375e2c4f702d1acd13f6d55df58.png

The code is:

HEADER

<style>

h2 { color: blue; }

td:nth-child(7)> span{

color: #ffffff;

padding: 4px 8px;

border: none;

border-radius: 3px;

width: 100px;

display: block;

text-align: center;

font-size: 14px;

font-weight: bold;

}

</style>

Where td:nth-child(7) is the position of the field to test.

 ---

FOOTER

<script>

document.addEventListener('DataPageReady', styleHandler);

function styleHandler(event) {

  const customizedField = document.querySelectorAll('td:nth-child(7) > span');

  customizedField.forEach(element => {

    if (element.innerHTML > 0 && element.innerHTML < 0.334) {

      element.style.backgroundColor="#09be13";

    }

    else if(element.innerHTML >= 0.334 && element.innerHTML < 0.501){

      element.style.backgroundColor="#8c2ab2";

    }

    else if(element.innerHTML >= 0.501 && element.innerHTML < 0.801){

      element.style.backgroundColor="#033bf3";

    }

    else if(element.innerHTML >=0.801 && element.innerHTML < 1.260){

      element.style.backgroundColor="#758d8d";

    }

    else if(element.innerHTML >=1.260 && element.innerHTML < 2.501){

      element.style.backgroundColor="#f7ff14";

      element.style.color="#20282B";

    }

    else if(element.innerHTML >=2.501 && element.innerHTML < 4.01){

      element.style.backgroundColor="#f7bb00";

      element.style.color="#20282B";

    }

    else if(element.innerHTML > 4){

      element.style.backgroundColor="#f83301";

    }

    });

  };

</script>

 

FIELD 7 (the cell to color)

<span>[@field:FullReactionIngredients_PRR#]</span>

---

 

All this is fine. However I now need to do the same for a calculated value field:

image.png.2ee0910ae6b5c346b782af4cd58e314d.png

Field 3 here is the value based on a parameter passed to the table through the URL:

CASE

WHEN (SELECT COUNT(DrugReactionID) FROM FullReactionIngredients WHERE DrugReactionID = '[@calcfield:3]') = 1

THEN

(SELECT CONVERT(VARCHAR, (PRR))

FROM FullReactionIngredients

WHERE DrugReactionID = '[@calcfield:3]' )

ELSE ' '

END

The value is calculated correctly and I have the same coloring code as shown above but with the value changed to td:nth-child(3).

So my question is; how can I get the CSS to work on a calculated field?

Thanks,

Steve

Link to comment
Share on other sites

  • 2 weeks later...

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...