【发布时间】:2019-02-12 06:39:07
【问题描述】:
我想在我的数据表中包含动态列标题和列数据。例如,我有日期选择器,我选择 2019 年 2 月 10 日到 2019 年 2 月 12 日之间的日期,所以我的数据表将有
February 10, 2019 | February 11, 2019 | February 12, 2019
作为列标题。如何实现这个输出?
这就是我构建数据表的方式
$("#tblClients").DataTable({
paginate: true,
pagingType: "full_numbers",
lengthChange: true,
filter: true,
info: true,
autoWidth: false,
columnDefs: [{
autoWidth: true,
"targets": [1]
}, {
"targets": [2, 3, 4, 5],
"sortable": false
}],
"oSearch": {
"bSmart": false
},
"dom": 'Bfrtip',
"buttons": [{
"extend": 'excelHtml5',
"text": 'Download',
"className": "btn btn-success",
}],
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
<table id="tblClients" class="table table-hover table-bordered">
<thead>
<tr>
<th>No.</th>
<th>Client</th>
<th>Name</th>
<th>Email Address</th>
<th>No. of Login</th>
<th>Last Logon Time</th>
</tr>
</thead>
<tbody>
<?php foreach($logData as $key => $log): ?>
<tr>
<td>
<?php echo $key+1; ?>
</td>
<td>
<?php echo $log['client']; ?>
</td>
<td>
<?php echo $log['name']; ?>
</td>
<td>
<?php echo $log['email']; ?>
</td>
<td>
<?php echo $log['counter']; ?>
</td>
<td data-sort="<?php echo $log['created']; ?>">
<?php
date_default_timezone_set('Asia/Manila');
echo date(DATE_FORMAT.' H:i:s', strtotime($log['created']));
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
【问题讨论】:
-
我为你创建了一个 sn-p。请用呈现的 HTML 替换 PHP - 除非您认为这是 PHP 问题
-
嗨@mplungjan sn-p在哪里
-
其他人编辑了您的问题。我会加回来的
-
您可能希望在 jquery 之后添加
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" /><script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> -
我们是在寻找 jquery 解决方案还是 php 解决方案?