简体   繁体   中英

Datatables datetime plugin not working

I want to sort my "Date Created" column in my table in latest date order. I saw a forum that uses the datetime datatable sorting plugin but it did not work fine. Can you help me figure this out? Here are my codes.

<script src="{{ asset('promed_admin/assets/js/jquery-1.10.2.js') }}"></script>

<script src="{{ asset('promed_admin/assets/js/jquery-1.12.0.min.js') }}"></script>

<script src="{{ asset('promed_admin/assets/js/jquery.dataTables.min.js') }}"></script>

 <script src="{{ asset('promed_admin/assets/js/bootstrap_latest.js') }}"></script>

<script src="{{ asset('promed_admin/assets/js/dataTables/moment.min.js') }}"></script>

 <script src="{{ asset('promed_admin/assets/js/dataTables/datetime-moment.js') }}"></script>

 $(function(){

          $.fn.dataTable.moment('YYYY-MM-DD HH:mm:ss');

          $('#table-prod-contents').DataTable({
              columnDefs : [
                  { type : 'date', targets : [10] }
              ]
          });

       });

My table

<table id="table-prod-contents" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th></th>
            <th>Product Name</th>
            <th>Description</th>
            <th>Type</th>
            <th>Unit</th>
            <th>Packaging</th>
            <th>Lot</th>
            <th>Price</th>
            <th>Quantity</th>
            <!--<th>Amount</th>-->
            <th>Expiry Date</th>
            <th>Date Created</th>
        </tr>
    </thead>

    <tbody>

    @foreach($products as $val)

       <tr class="tbl-prod-row">
         <td><input type='checkbox'<?php //echo (($user_level == $admin_text) ? "" : 'disabled=disabled'); ?> style='width:30px; height:20px;' class='radio_check_all prod-id-checkbox' id='radio_check_all prod-id-checkbox' value="{{ $val->id }}"></td>
         <td><input type="hidden" display="none" class="pharma" value="{{ $val->pharmaceutical }}">{{ $val->pharmaceutical }}</input></td>
         <td>{{ $val->description }}</td>
         <td>{{ $val->type }}</td>
         <td>{{ $val->unit }}</td>
         <td>{{ $val->packaging }}</td>
         <td>{{ $val->lot }}</td>
         <td style="text-align:center;">{{ $val->price }}</td>
         <td style="color:#fff; text-align:center; <?php echo (( $val->quantity <= 10 ) ? "background-color:#C00" : "background-color:#25A602" ); ?>">{{ $val->quantity }}</td>
         <!--<td style="text-align:center;">{{ $val->amount }}</td>-->
         <td>{{ $val->expiry_date_month }}</td>
         <td>{{ $val->created_at }}</td>
       </tr>

    @endforeach

    </tbody>

</table>

Table Output: 在此处输入图片说明

Database table

在此处输入图片说明

Since the date strings moment.js returns is Date.parse() able' you can do this :

columnDefs : [
    { type : 'date', targets : [13] }
], 

Result: http://jsfiddle.net/t6snpgkf/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM