coloring a row (ajax data)

coloring a row (ajax data)

zinghzingh Posts: 1Questions: 0Answers: 0
edited February 2010 in General
hi,

I am trying to color a row of the datatable but I am no jquery expert. How can i access the elements of the data table. My plan is to color rows where some values are smaller than a certain value differently.
Here is what i found in the Examples:

[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
if ( aData[2] < 1 )
{
$('td:eq(2)', nRow).css("color","grey");
}
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You can use the API function fnGetNodes if you want to do it at any old point ( http://datatables.net/api#fnGetNodes ). Or if you want to do it when the table finishes it's initialisation you can use fnInitComplete (and fnGetNodes): http://datatables.net/usage/callbacks#fnInitComplete . Or you could use fnRowCallback (and return the row!) if you wanted - although this is run for every time the row is displayed so could be considered sub-optimal.

    Regards,
    Allan
  • gmeridethgmerideth Posts: 7Questions: 0Answers: 0
    If anyone in the future is looking for this example, I did it via:

    [code]
    "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
    $('td', nRow).closest('tr').css('background', aData[6] === true ? '#eef' : '#fff');
    return nRow;
    }
    [/code]

    In my case, the row color is set either light blue or white depending on the value (true/false) of the hidden column [6]. This sets the colors for *each* row regardless of how many but for my purposes the table will hold no more than 600 elements. There is no noticeable delay on any of the end users browsers.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited July 2011
    -- edit -- nevermind
This discussion has been closed.