Conditional format of cell

Conditional format of cell

AndyMPBAAndyMPBA Posts: 2Questions: 1Answers: 0

Hi
I am completely new to all this. I have managed to display a table with this javascript:

jQuery(function(){jQuery('#gbintl_entries').DataTable();});

My table has 8 columns, and the last column has the text "Paid" or "Not Paid". What I would like to do is make this cell background Green if "Paid" and Red if "Not Paid"
Columns:

<

table id="gbintl_entries" class="display" data-page-length='25'>
<thead>
<tr bgcolor="#a8a7a8">
<td><strong>First Name</strong></td>
<td><strong>Last Name</strong></td>
<td><strong>Junior?</strong></td>
<td><strong>Country</strong></td>
<td><strong>Class(es)</strong></td>
<td><strong>Banquet Tickets</strong></td>
<td><strong>Date Entered</strong></td>
<td><strong>Paid?</strong></td>
</tr>
</thead>

I have tried many variations of this:

$('#gbintl_entries').dataTable( {
"createdRow": function( row, data, dataIndex ) {
if ( data[7] == "Paid" ) {
$(row).addClass( 'important' );
}
}
} );

But I don't even know where to put it or where I should put the 'class'

Answers

  • kthorngrenkthorngren Posts: 21,350Questions: 26Answers: 4,955

    See if this example helps:
    http://live.datatables.net/muyemace/1/edit

    Note this is needed for the CSS to highlight the whole row

    table#example.dataTable tbody tr.Highlight_inUse > .sorting_1 {
        background-color: #ffa;
    }
    
    table#example.dataTable tbody tr.Highlight_inUse {
        background-color: #ffa;
    }
    
    

    Kevin

  • AndyMPBAAndyMPBA Posts: 2Questions: 1Answers: 0

    Thank you

This discussion has been closed.