Conditional colouring

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
eagle
Veteran Member
Posts: 39
Joined: 2013-01-09 15:38

Conditional colouring

Post by eagle » 2014-05-09 13:46

I have a colum that shows an integer from 1-5.

In table view I would like to show the cell background based on the value of the cell.

E.g.

If the value is 1, then 1 is presented with a blue cell background.
If the value is 2, then 2 is presented with a red cell background.

I guess I can do this by adding some javascript to my table TV template, but would really appreciate some hints in the right direction.

Thanks a lot.

eagle
Veteran Member
Posts: 39
Joined: 2013-01-09 15:38

Re: Conditional colouring

Post by eagle » 2014-05-12 12:55

I managed to solve this one by myself eventually...

For any other interested parties:

In this case my colum is called 'b'.

Edit /templates/myapp_templateTV.html

Find

Code: Select all

		<td id="myapp-b-<%%VALUE(id)%%>" class="myapp-b text-center"><%%VALUE(b)%%></td>
Replace with:

Code: Select all

<td id="myapp-b-<%%VALUE(id)%%>" class="myapp-b text-center"><script>
if ('<%%VALUE(b)%%>' == 1){document.write('<div style="background-color:#00FF00;font-weight: bold"><%%VALUE(b)%%></div>');}
else if ('<%%VALUE(b)%%>' == 2){document.write('<div style="background-color:#008000;font-weight: bold"><%%VALUE(b)%%></div>');} 
else if ('<%%VALUE(b)%%>' == 3){document.write('<div style="background-color:#FFFF00;font-weight: bold"><%%VALUE(b)%%></div>');} 
else if ('<%%VALUE(b)%%>' == 4){document.write('<div style="background-color:#FF8000;font-weight: bold"><%%VALUE(b)%%></div>');} 
else if ('<%%VALUE(b)%%>' == 5){document.write('<div style="background-color:#FF0000;font-weight: bold"><%%VALUE(b)%%></div>');}
else {document.write('<div><%%VALUE(b)%%></div>');}
</script> </td>

Post Reply