Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:54:26+00:00 2026-06-12T13:54:26+00:00

I´m trying to change the row color depending on a value, for a server

  • 0

I´m trying to change the row color depending on a value, for a server side loaded datatable, but it’s not working. I’m using a code like this one on my javascript:

$('#table').dataTable({
     'bServerSide': true,
     'bProcessing': true,
     'sAjaxSource': 'datatables/my_ajax.php',
     'iDisplayLength': 50,
     "sPaginationType": "bootstrap",
     "fnInitComplete": function(oSettings) {
         for (var i = 0, iLen = oSettings.aoData.length; i < iLen; i++) {
             if (jQuery.inArray(oSettings.aoData[i]._aData[2], food_types) != -1) {
                 oSettings.aoData[i].nTr.className = "myClass";
             }
         }
     },

myClass looks like:

.myClass{ 
    background-color: red;
}

.myClass td {
   background-color: red; 
}

So, basically when the second <td> of each row has a value that appears on the food types array, the class should be changed to myClass. This part is working (I can see with firebug that the class has changed), however I cannot see the change (I don’t see the row turning to red background). What am I missing? Also, is this a good approach or a cleaner way would be to change the color from ajax directly? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:54:27+00:00Added an answer on June 12, 2026 at 1:54 pm

    Looks like your dataTable’s CSS wrapper is overwriting your style .. Maybe that the reason you do not see the change in the backgroundcolor..

    Looks like you need to change the class on which it is being applied..

    Maybe more in these terms

    table.display.myClass 
    {
    
     background-color: red !important
    }
    
    table.display.myClass td
    {
    
     background-color: red !important
    }
    

    More like guessing the wrapper as i have no idea about the exact classes being applied by the datatables plugin..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to change the header color and the row color of the
I'm trying to change the font color of a row in a datagrid if
I am trying to create a drawable in code and change the color based
I am trying to create a drawable in code and change the color based
I am trying to figure out how to change the row background color when
I've been trying everything I know to change the color of a row in
I've spend a lot of time trying to change row text color on CheckBox
i am trying to change the background color of the selected row in a
I am trying to change the row color of a DataList Control... <asp:DataList ID=dlTrades
Ive been trying to change the background color of a row in the Compact

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.