weixin_33726318 2019-01-01 20:29 采纳率: 0%
浏览 21

一列显示数据

I am working with jQuery datatables. I am executing the following sql statement:

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

With the option columnDefs I am trying to show the data in a specific column: columnDefs targets 0 created the column for 'status' columnDefs targets 1 created the column for 'internal_id' etc.

Now what I want is I want to show the data for "name", "address" and "city" in one column. In SQL I can realize this by using concat. But this is not what I want. I want define the columns in columnDefs so I will be able to change the style of the data.

Does someone know what I need to change in my jQuery to put the "name", "address" and "city" in one column?

Here is my 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条回答 默认 最新

  • weixin_33737134 2019-01-01 23:57
    关注

    You can modify columns.render option and access full data set using third argument full to produce cell content using multiple values.

    For example:

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

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧