[英]JQuery Datatable Sort Date column in a simple way
我的日期列排序不正確,看起來像對正常數字而不是正確的日期列進行排序。
我在應用程序中使用的所有數據表都使用下面的javascript,因此它對所有數據表都是通用的,這就是為什么我不設置列信息,而是讓數據表自動選擇它。 這樣可以使我的日期列正確排序嗎? 還是我必須設置諸如列格式之類的內容?
table.dataTable({
stateSave: true,
"bLengthChange": false,
"bFilter": searchable,
"columnDefs": [{
"orderable": false,
"targets": [0]
}],
"order": [
[1, 'asc']
],
"bSort": true,
"lengthMenu": [
[10, 20, 50, 100, 150, -1],
[10, 20, 50, 100, 150, "All"]
],
"iDisplayLength": 10,
"pageLength": 10
});
下面是我的看法,我使用MVC
<table class="table table-bordered" id="datatableList">
<thead class="heading">
<tr>
<th class="table-checkbox"><input type="checkbox" class="group-checkable" /></th>
<th>ID</th>
<th>Date</th>
<th>Account Name</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.AllLabourCharges.OrderByDescending(x => x.Date))
{
<tr>
<td><input type="checkbox" class="checkboxes" value="@item.Id" /></td>
<td>@Html.ActionLink(item.Id.ToString(CultureInfo.InvariantCulture).PadLeft(4, '0'), "Form", new { item.Id })</td>
<td>@item.Date.Date.ToString(GeneralHelper.DateFormat)</td>
<td>@Html.EmptyIfNull(x => item.Account.AccountName)</td>
</tr>
}
</tbody>
</table>
在我的參考資料下方:
<script src="~/Content/assets/global/plugins/select2/select2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="~/Content/assets/global/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="~/Content/assets/global/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="~/Content/assets/global/plugins/datatables/extensions/Scroller/js/dataTables.scroller.min.js"></script>
<script type="text/javascript" src="~/Content/assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js"></script>
您需要首先定義所有列。
您的數據應為准確的格式,如日期格式應為javascript date,因此可以為日期添加更多內容。
您可以在顯示日期值中添加隱藏的日期值。
我遇到與日期字段相同的問題,並解決上述解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.