1

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.

1 Answer 1

1

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>';
    }
 },
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Dude, i was going on this solution i found andersontorres.com.br/hacks-e-outras-coisas/… thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.