Jump to content

Conditionally set cell back ground color


Recommended Posts

Hello @SteveMott,

Please add this script into the Footer section (don`t forget to disable the HTML editor on the Advanced tab before pasting):

<script>
if(typeof colorHandler == 'undefined') {

    function colorHandler() {
        const coloredField = document.querySelectorAll('td:nth-child(1)'); // 1 is the field order number that needed to be colored
        const conditionField = document.querySelectorAll('td:nth-child(9)'); // 9 is the field order number that stores condition
     
        conditionField.forEach((cell, index) => {
           if (cell.innerHTML === '1') {
                coloredField[index].style.backgroundColor = '#3EB489'; //change the color code if needed
           }       
        });

  document.removeEventListener('DataPageReady', colorHandler);
}
document.addEventListener('DataPageReady', colorHandler);
  
}
</script>

Feel free to update this thread if you have further questions. 

Link to comment
Share on other sites

Hi CoopperBackpak

 

I've put your code in and the coloring occurs in cell 2 of the wrong row.

In the attached image the last column indicates the result of calculated field 3 (value is 0 or 1). The change to the background appears in cell 1,  4 rows up

Can't figure it from the code!

Thanks

Steve

PharmAdvisor3.png

Link to comment
Share on other sites

@SteveMott, thank you.

It looks strange :(
Could you test this code instead?

<script>
document.addEventListener('DataPageReady', colorHandler);

    function colorHandler(event) {
        const coloredField = document.querySelectorAll('.cbResultSetDataRow td:nth-child(1)'); 
        const conditionField = document.querySelectorAll('.cbResultSetDataRow td:nth-child(9)'); 

        conditionField.forEach((cell, index) => {
           if (cell.innerHTML === '1') {
                coloredField[index].style.backgroundColor = '#3EB489'; 
           }       
        });

  document.removeEventListener('DataPageReady', colorHandler);
}
</script>

 

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