我已经尝试修改我的代码,按日期订购我的表记录(按日期字段排序"开始日期/时间"和"完成日期/时间" )但没有成功。我使用现有的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>';
答案 0 :(得分:0)
在您的代码中,我可以看到您正在使用jQuery
,您可以使用插件,它将为您提供您正在寻找的确切功能,而您无需重新发明轮子。我使用jQueries dynatable
(link)插件,现在没有后悔!