Reputation: 433
i m using datatables w/ server-side processing, everything work perfect, but i dont know how i can use a php function on data output.
i have this code
$('#exampless').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "data/load-anunciantes.php",
"columnDefs": [ {
"targets": -2,
"data": 7, // STATUS 1 or 0
} ]
} );
the column 7 return 1 or 0 its fine but i want to do something like this.
on php i was doing
status($status);
if status = 1 i return <label class=\"green\">Active</label>
and
if status = 0 i return <label class=\"red\">Inactive</label>
Thanks for any advice.
Upvotes: 1
Views: 294
Reputation: 4918
You need to use render
or mRender
(depending on which version of datatables you're using):
"columnDefs": [ {
"render": function ( data, type, row ) {
if(row[7] == 1){
return '<label class=\'green\'>Active</label>';
}else{
return '<label class=\'red\'>Inactive</label>';
}
},
Upvotes: 1