【发布时间】:2019-01-01 20:29:04
【问题描述】:
我正在使用 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>
【问题讨论】:
标签: jquery ajax datatables