Change text color based on value

Change text color based on value

dabaqdabaq Posts: 6Questions: 3Answers: 0

I'm trying to work out some conditional formatting for column 4 and 5, based on these criteria:

if value <= 0, color here
if value => 1, color here
if value => 2, color here
if value => 3, color here
if value => 4, color here
if value => 5, color here

I've read I need to use rowcallback in order to use this, but I can't get my head around it.

Best regards

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    If its just the text colour, use a renderer and put it in a span with the correct colour for the value.

    Allan

  • dabaqdabaq Posts: 6Questions: 3Answers: 0

    Thank you for your reply Allan. However I have no idea how to do that, I'm very new to this. Could you point me in the right direction? I thought I could get away with a simple if else statement.

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736
    Answer ✓

    Maybe this example will help:
    http://live.datatables.net/sifukito/1/edit

    Kevin

  • dabaqdabaq Posts: 6Questions: 3Answers: 0

    Thanks Kevin, that's what I was looking for.

  • junmonkjunmonk Posts: 1Questions: 0Answers: 0

    @kevin, how to change color for two columns which have different values, say column 5 has Yes/No and column 7 has Locked/Unlocked. thanks

  • SerennaSerenna Posts: 2Questions: 0Answers: 0

    Is there a way that I can put the color in it's specific <td> ?
    I want to avoid putting the <span> tag cause it'll blow other script that I have.
    I wish to highlight the 'Waiting definition' value in a specific column and I think that if I could add the class above in <td>s that have this value it'd be perfect

    .redText {
    color:#F00 !important;
    }

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @Serenna ,

    Yep, see this example here.

    Cheers,

    Colin

  • SerennaSerenna Posts: 2Questions: 0Answers: 0

    Thank you very much!

This discussion has been closed.