数据表格式数据输出

时间:2014-12-11 14:49:48

标签: php jquery datatables jquery-datatables

我使用数据表与服务器端处理,一切都很完美,但我不知道如何在数据输出上使用PHP函数。

我有这个代码

$('#exampless').dataTable({

  "bProcessing": true,
    "bServerSide": true,

    "sAjaxSource": "data/load-anunciantes.php",     

     "columnDefs": [ {
        "targets": -2,
        "data": 7, // STATUS 1 or 0

    } ]



} );

第7列返回1或0它的罚款,但我想做这样的事情。

在php上我正在做

status($status);

如果status = 1,则返回<label class=\"green\">Active</label>

如果status = 0,我返回<label class=\"red\">Inactive</label>

感谢您的任何建议。

1 个答案:

答案 0 :(得分:1)

您需要使用rendermRender(取决于您正在使用的数据格的版本):

"columnDefs": [ {
"render": function ( data, type, row ) {
    if(row[7] == 1){
        return '<label class=\'green\'>Active</label>';
    }else{
       return '<label class=\'red\'>Inactive</label>';
    }
 },