【发布时间】:2017-09-20 11:49:21
【问题描述】:
我尝试修改代码以按日期对表记录进行排序(按日期字段“开始日期/时间”和“完成日期/时间”排序时),但没有成功。我使用现有的 SO 解决方案来尝试让排序工作,但如果有人可以提供帮助,我将不胜感激。
我的表格 HTML 和数据由我的 ajax 文件提供。
HTML:
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Existing Log Entries</h3>
</div>
<form role="form">
<div class="box-body">
<div class="col-md-12" id="div-log-list"></div>
</div>
<div class="box-footer">
</div>
</form>
<div style="margin:auto; width:99%;">
<div id="entrieslist-div"></div>
</div>
<div class="overlay" id="box-loading">
<i class="fa fa-refresh fa-spin"></i>
</div>
</div>
JS:
$(function() {
// Populate log entry table
$.ajax({
type: "post",
url: "ajax/ajax-populate-log-entries.php",
success: function(result){
$('#entrieslist-div').html(result);
$('#box-loading').hide();
$("#entrieslist").dataTable();
}
});
});
AJAX:
$counter = 0;
echo '<table id="entrieslist" class="table table-bordered table-striped dataTable">';
echo '
<thead>
<tr>
<th>Start Date/Time</th>
<th>Finish Date/Time</th>
<th>Server Name</th>
<th>Carried Out By</th>
<th>Verified By</th>
<th>Authorised By</th>
<th>Work Carried Out</th>
<th>Work Verification</th>
<th>Change Reason</th>
<th>Perceived Impact</th>
<th>Rollback Process</th>
</tr>
</thead>
';
echo '<tbody>';
foreach( $lines as $row) {
echo '<tr>';
echo '
<td>'.$row['start_date_time'].'</td>
<td>'.$row['finish_date_time'].'</td>
<td>'.$row['server_name'].'</td>
<td>'.$row['carried_out_by'].'</td>
<td>'.$row['verified_by'].'</td>
<td>'.$row['authorised_by'].'</td>
<td>'.$row['work_carried_out'].'</td>
<td>'.$row['work_verified'].'</td>
<td>'.$row['change_reason'].'</td>
<td>'.$row['perceived_impact'].'</td>
<td>'.$row['rollback_process'].'</td>
';
echo '</tr>';}
$counter++;
echo '</tbody>';
echo '<tfoot>
<tr>
<th>Start Date/Time</th>
<th>Finish Date/Time</th>
<th>Server Name</th>
<th>Carried Out By</th>
<th>Verified By</th>
<th>Authorised By</th>
<th>Work Carried Out</th>
<th>Work Verification</th>
<th>Change Reason</th>
<th>Perceived Impact</th>
<th>Rollback Process</th>
</tr>
</tfoot>';
echo '</table>';
【问题讨论】:
-
你不能在 php 文件中对记录进行排序,然后它可以在结果中可见
-
问题很可能是日期呈现为字符串而不是日期时间。您可能可以使用 js 插件来解决它,例如this。
标签: javascript html ajax datatables datatables-1.10