日期间隔的数据表和日期时间格式不可排序
Datatables and DateTime format of interval between dates not sortable
我有一张包含截止日期和付款日期的发票 table。我有第三列是付款日期和到期日期之间的时间。我使用 DateTime 和格式来获取付款延迟了多少天。
$pDate = date("Y-m-d H:i:s",$paidDate);
$dDate = date("Y-m-d H:i:s",$dueDate);
$pDate = new DateTime($pDate);
$dDate = new DateTime($dDate);
$diff = $pDate->diff($dDate);
$pastDueFormat = $diff->format('%a');
我试过将格式更改为
$pastDueFormat = $diff->format('%d');
我将所有这些数据都保存在一个 table 格式的 DataTables
中
$('#invoices').dataTable();
问题是,我无法将 39 天识别为一个数字,甚至无法识别 39 天。我的排序结果总是
94
91
9
88
85
8....
明明我想要的时候
94,91,88,85,9,8.....
看起来 DataTables 并不是那么聪明。您可以像这样显式提供列类型:
$('#invoices').dataTable({'columnDefs': [{'type': 'num', 'targets': 0}]});
'targets'
键的值应等于您的列的索引,从 0 开始。
我有一张包含截止日期和付款日期的发票 table。我有第三列是付款日期和到期日期之间的时间。我使用 DateTime 和格式来获取付款延迟了多少天。
$pDate = date("Y-m-d H:i:s",$paidDate);
$dDate = date("Y-m-d H:i:s",$dueDate);
$pDate = new DateTime($pDate);
$dDate = new DateTime($dDate);
$diff = $pDate->diff($dDate);
$pastDueFormat = $diff->format('%a');
我试过将格式更改为
$pastDueFormat = $diff->format('%d');
我将所有这些数据都保存在一个 table 格式的 DataTables
中$('#invoices').dataTable();
问题是,我无法将 39 天识别为一个数字,甚至无法识别 39 天。我的排序结果总是
94 91 9 88 85 8....
明明我想要的时候 94,91,88,85,9,8.....
看起来 DataTables 并不是那么聪明。您可以像这样显式提供列类型:
$('#invoices').dataTable({'columnDefs': [{'type': 'num', 'targets': 0}]});
'targets'
键的值应等于您的列的索引,从 0 开始。