2017-09-20 12 views
0

私のコードを修正して日付でテーブルレコードを注文しようとしましたが(日付フィールド "Start date/Time"と "Finish Date/Time"で注文する)、成功しませんでした。私は既存の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

PHPファイル内のレコードを並べ替えることはできません。結果に表示される可能性があります。 –

+0

日付はdatetimeの代わりに文字列としてレンダリングされる可能性があります。おそらくjsプラグインを使用して[this](https://jsfiddle.net/3vLLvscr/19/)のように解決することができます。 – markpsmith

答えて

0

あなたのコードのように私はあなたがその意志でプラグインを使用することができjQueryを使用している見ることができますあなたが探している正確な機能をお届けし、ホイールを再開発する必要はありません。私はjQueries dynatablelink)プラグインを使用しており、今のところそれを後悔していません!

関連する問題