Coloring row if..
Coloring row if..
Alex2019
Posts: 62Questions: 9Answers: 0
Hello,
i have this code for the table
$(document).ready(function() {
var oldStart = 0;
$('#tblFem').dataTable({
"bJQueryUI": true,
"order": [[ 1, "asc" ]],
"dom": '<lfi<t>ip>',
"sPaginationType": "full_numbers",
"fnDrawCallback": function (o) {
if ( o._iDisplayStart != oldStart ) {
var targetOffset = $('#tblFem').offset().top;
$('html,body').animate({scrollTop: targetOffset}, 500);
oldStart = o._iDisplayStart;
}
}
});
} );
I would like to display the colored lines only if there is a word
example:
if (data [5] == "Active") {
$ (row) .addClass ('green');
}
if (data [5] == "Retired") {
$ (row) .addClass ('red');
I tried to enter the code but it doesn't work
$(document).ready(function() {
var oldStart = 0;
$('#tblFem').dataTable({
"bJQueryUI": true,
"order": [[ 1, "asc" ]],
"dom": '<lfi<t>ip>',
"createdRow": function( row, data, dataIndex ) {
if ( data[5] == "Active" ) {
$(row).addClass('green');
}
if ( data[5] == "Retired" ) {
$(row).addClass('red');
}
"sPaginationType": "full_numbers",
"fnDrawCallback": function (o) {
if ( o._iDisplayStart != oldStart ) {
var targetOffset = $('#tblFem').offset().top;
$('html,body').animate({scrollTop: targetOffset}, 500);
oldStart = o._iDisplayStart;
}
}
});
} );
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Are you saying want those lines entirely removed? If so, you could either remove them before you initialise DataTables, or within
initComplete
callrow().remove()
,Colin
Hi Colin
do not remove them,
color them with these words
Active = Green
Retired = Red
the code I entered is probably wrong
thanks
What happens?
You post this but it looks like you don't have the closing
}
forcreatedRow
which should result in a syntax error in the browser's console:If this doesn't help then please post a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I hadn't noticed the error
thanks kthorngren
Sorry, I entirely misread that. Yep, Kevin's solution works, or you could do something like this: http://live.datatables.net/vejupiva/2/edit
Colin
Colin hi,
there is an error in your code
http://live.datatables.net/vejupiva/2/edit
Line 36: Missing semicolon.
Hi Colin,
it also works with your code
Thanks