一列显示数据

时间:2019-01-01 20:29:04

标签: jquery ajax datatables

我正在使用jQuery数据表。我正在执行以下sql语句:

SELECT status, internal_id, name, address, city, id FROM `relations` 

使用选项columnDefs我试图在特定列中显示数据: columnDefs目标0为“状态”创建了列 columnDefs目标1为“ internal_id”创建了列 等

现在我想要的是我想在一列中显示“名称”,“地址”和“城市”的数据。在SQL中,我可以通过使用concat来实现。但这不是我想要的。我想在columnDefs中定义列,以便能够更改数据的样式。

有人知道我需要在jQuery中进行哪些更改,以将“名称”,“地址”和“城市”放在一栏中吗?

这是我的jQuery:

<script type="text/javascript">
  $( document ).ready(function() {
    $('#employee_grid1').DataTable({
      "bprocessing": true,
      "serverSide": true,
      "ajax": {
    "url": "response1.php",
    "type": "POST",
    "error": function(){
      $("#employee_grid_processing").css("display","none");
    }
      },
      "columnDefs": [ 
    { "targets": 0, "render": function ( data, type, full, meta ) { return  ' ' + (data == 0 ? '<center ><i class="fa fa-university" aria-hidden="true"></i>' : (data == 1 ? '<i class="fa fa-university" aria-hidden="true"></i>' : '<i class="fa fa-briefcase" aria-hidden="true"></i>')) + ' '} },
    { "targets": 1, "render": function ( data, type, full, meta ) { return  '<center>'+data+'</center>'} },
    { "targets": 2, "render": function ( data, type, full, meta ) { return  '<table><tr><td>'+data+'</td></tr>'} },
    { "targets": 3, "render": function ( data, type, full, meta ) { return  '<td>'+data+'</td>'} },
    { "targets": 4, "render": function ( data, type, full, meta ) { return  '<td>'+data+'</td></table>'} }              
      ]                
    });   
  });
</script>

1 个答案:

答案 0 :(得分:0)

您可以修改columns.render选项并使用第三个参数full访问完整数据集,以使用多个值生成单元格内容。

例如:

{ 
    "targets": 2, 
    "render": function ( data, type, full, meta ) { 
        return  'Name: ' + full[2] + '<br>Address: ' + full[3] + '<br>City: ' + full[4]; 
    } 
},
相关问题