按日期列对数据表进行排序

时间:2018-05-21 10:01:20

标签: datatables

我试图按第3列(日期列)对我的数据表进行排序但是它似乎只按日期列中的第一个数字排序,如下图所示我如何才能得到它以便按日期排序比数字?

 echo "<table>
<thead>
<th>Zone</th>
<th>Popularity</th>
<th>Date</th>
</thead>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['count(location)'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";}
echo "</table>";
mysqli_close($con);
?>
<script>
$('table').DataTable( {
dom: 'Bfrtip',
"order": [[ 2, "desc" ]],
buttons: [
    'copy', 
    {
        extend: 'csv',
        text: 'CSV',
        extension: '.csv',
        exportOptions: {
            modifier: {
                page: 'current'
            }
        },
        title: 'table'
    }, 
    'pdf',
'print', ],

} );
</script>

table

1 个答案:

答案 0 :(得分:0)

我找到了问题的可能解决方案here

建议的解决方案是按照this指南指定日期列的日期格式(因为DataTables可能无法立即检测到它)。您可能需要使用moment.js来解决此问题。

相关问题