我受命在此PHP应用程序中修复此表排序。该表使用DataTable 1.10自动生成php blade.php
文件的数据表。
进入页面的数据使用以下格式作为“发布日期”:
uploaded_at:“ 2018-01-02 00:00:00”
page.blade.php
<table class="table tbl_issue" cellspacing="0" style="border: 1px solid #e9ecef;border-radius: 4px;">
<thead>
<tr>
<th>Issue Title</th>
<th>Publish Date</th>
</tr>
</thead>
<tbody>
@if(count($data['issues']))
@foreach($data['issues'] as $issue)
@if($issue->uploaded_at >= $data['starts_date'])
<tr>
<td>
{{$issue->name}}
</td>
<td>{{date('m/d/Y', strtotime($issue->uploaded_at))}}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
$(document).ready(function(){
$('.tbl_issue').DataTable();
});
当我单击自动生成的“发布日期”过滤器时,日期未正确排序。 (下图)
如您所见,08/18/2016
日期总是在中间。
如何正确获取此排序日期?
答案 0 :(得分:1)
尝试使用Datatables API将该列设置为日期类型。
示例:
$('#example').dataTable( {
"columns": [
{ "type": "string" },
{ "type": "date" },
]
} );
请参阅参考资料: