我想按我最近的日期順序排序我的表中的「Date Created」列。我看到一個使用datetime datatable排序插件的論壇,但它不能正常工作。你能幫我弄清楚這一點嗎?這是我的代碼。Datatables datetime插件不工作
<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] }
]
});
});
我的表
<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>
數據庫表
嗨了!你有任何JS錯誤?你有沒有包含DataTables jQuery插件? – mineroot
沒有錯誤。看看上面的JavaScript包含文件的列表。 – Eli