[RESOLVED] Assign a class depending on value?

[RESOLVED] Assign a class depending on value?

VrutinVrutin Posts: 14Questions: 0Answers: 0
edited November 2013 in General
How can I apply class to an element:

var sOut =
'' +
'' +
'Web:' + '' + oData.UK + '' + '' +
'Print:' + oData.job_name + '' +
'' +
'';
return sOut;

so for example "if(oData.UK == 7)" I can apply a css class?

Regards,
Vrutin

Replies

  • kiwykiwy Posts: 5Questions: 0Answers: 0
    Hello,
    I don't know how you're using datatables but you should consider using the function fnRowCallbacks.
    here's the documentation of such a function:
    http://datatables.net/usage/callbacks
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Or fnCreatedCell which will probably be more efficient.

    Allan
  • VrutinVrutin Posts: 14Questions: 0Answers: 0
    Thanks both for the help,

    However, I had inserted span elements inside the td, so not sure if the above mentioned methods would have worked.

    http://awesomescreenshot.com/0822079ge9

    However, the way I worked around this issue was the following way (if it helps anyone in future):
    [code]
    $(document).ready(function() {
    $('#example td.control').live('click', function() {
    var statues = $('.status-digits');
    $(statues).each(function() {
    switch ($(this).text()) {
    case '7':
    $(this).css('background-color', '#90B200');
    break;
    case '6':
    $(this).css('background-color', '#cc9966');
    break;
    case '5':
    $(this).css('background-color', '#ff6699');
    break;
    case '4':
    $(this).css('background-color', '#66ccff');
    break;
    case '3':
    $(this).css('background-color', '#F5F241');
    break;
    case '2':
    $(this).css('background-color', '#cc66ff');
    break;
    case '1':
    $(this).css('background-color', 'orange');
    break;
    case '0':
    $(this).css('background-color', '#ff3333');
    break;
    case 'null':
    $(this).text('');
    $(this).css('background-color', 'rgba(0,0,0,0)');
    break;
    }
    });
    });
    })
    [/code]

    Again, thanks for all the help.

    Regards,
    Vrutin
This discussion has been closed.