Change TR class based on data
Change TR class based on data
organicspider
Posts: 12Questions: 0Answers: 0
Hello,
First of all must say what an awesome piece of code this is :)
Now the question ... I am trying to highlight a row based on a value from returned data in an external script. Here is the code I have so far[code]
$(document).ready(function() {
$('#asterisk-cdr tbody tr').each( function() {
var sClass;
var nTds = $('td', this);
var sDirection = $(nTds[6]).text();
if ( sDirection == "0" )
sClass = "inbound";
else
sClass = "outbound";
this.setAttribute( 'class', sClass );
} );
$('#asterisk-cdr').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumnDefs": [ { "sClass": "center", "aTargets": [ 0, 1, 2, 3, 4, 5, 6 ] } ],
"aoColumns": [ null, null, null, null, null, null, { "bVisible": false } ],
"sAjaxSource": "/media/php/cdr.php"
} );
} );[/code]The sixth field in the recordset is 'direction' which can be either 0 or 1. I am guessing where setAttribute is called I should be using something else other than class ?
First of all must say what an awesome piece of code this is :)
Now the question ... I am trying to highlight a row based on a value from returned data in an external script. Here is the code I have so far[code]
$(document).ready(function() {
$('#asterisk-cdr tbody tr').each( function() {
var sClass;
var nTds = $('td', this);
var sDirection = $(nTds[6]).text();
if ( sDirection == "0" )
sClass = "inbound";
else
sClass = "outbound";
this.setAttribute( 'class', sClass );
} );
$('#asterisk-cdr').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumnDefs": [ { "sClass": "center", "aTargets": [ 0, 1, 2, 3, 4, 5, 6 ] } ],
"aoColumns": [ null, null, null, null, null, null, { "bVisible": false } ],
"sAjaxSource": "/media/php/cdr.php"
} );
} );[/code]The sixth field in the recordset is 'direction' which can be either 0 or 1. I am guessing where setAttribute is called I should be using something else other than class ?
This discussion has been closed.
Replies
$(document).ready(function() {
$('#asterisk-cdr').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumnDefs": [ { "sClass": "center", "aTargets": [ 0, 1, 2, 3, 4, 5, 6 ] } ],
"aoColumns": [ null, null, null, null, null, null, { "bVisible": false } ],
"sAjaxSource": "/media/php/cdr.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var sDirectionClass;
if ( aData[6] == "0" )
sDirectionClass = "inbound";
else
sDirectionClass = "outbound";
$(nRow).addClass( sDirectionClass );
return nRow;
}
} );
} );
[/code]
Many thanks for this. As no one else responded you could have just left the question open, but your answer meant that I found your solution to my problem within minutes. Many thanks
Tony