数据表排序字符串作为日期格式

时间:2019-04-23 06:56:49

标签: javascript jquery html datatable bootstrap-4

我有一个数据表,用于从api提取数据,并且它的date列为字符串格式。现在,我想按降序对日期进行排序,其格式为dd / mm / yyyy。我已经尝试过了但是我却无法正常工作。

HTML:

     <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
      <link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.2.3/css/responsive.bootstrap.min.css">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> 
      <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script> 
      <script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script> 
      <script src="https://cdn.datatables.net/responsive/2.2.3/js/responsive.bootstrap4.min.js"></script> 
 <table class="table table-bordered" id="example" width="100%" cellspacing="0">
                           <thead>
                              <tr>
                                 <th>Position</th>
                                 <th>Location</th>
                                 <th>Experience</th>
                                 <th>Type</th>
                                 <th>Job Posted</th>
                                 <th>Status</th>
                                 <th>Edit</th>
                                 <th>Delete</th>
                              </tr>
                           </thead>
                        </table>

脚本:

<script type="text/javascript">
         $(document).ready(function(){
             var table = $('#example').DataTable( {
               "order": [[ 4, "desc" ]] ,
                  responsive: true,
                  "processing" : true,
                  "ajax" : {
                         "url" : "http://localhost:3000/api/joblists",
                        dataSrc : ''
                  },
                  "columns" : [ {
                        "data" : "position"
                  }, {
                        "data" : "location"
                  }, {
                        "data" : "experience"
                  }, {
                        "data" : "type"
                  },{
                        "data" : "jobposted"
                  },{
                        "data" : "status"
                  },
                  {
                     "mData": "Edit",
                     "mRender": function (data, type, row) {
                        return "<a  href='../../.././admin/edit-job.html?id=" + row.id + "'>Edit</a>";
                     }
                  },
                  {
                     "mData": "Delete",
                     "mRender": function (data, type, row) {
                        return "<a class='delete'  data-id=" + row.id + " href='../../.././admin/job-insert.html?data-id=" + row.id + "' >Delete</a>";
                     }
                  }]
             } );

         });
      </script>

我尝试使用“ order”:[[4,“ desc”]],但是它不是按降序排序。帮我实现这个目标。

0 个答案:

没有答案