Javascript Jquery Datatable-日期排序不适用于月份(相对于日期的月份)
数据表排序,包含除日期以外的所有内容。只使用datedays排序,不考虑其月份。 我有DD-MM-YYYY格式的日期,它是动态地从数据库中获取的。但有些日期也在另一个月之间 我使用了Jquery-3.3.1.js和Datatable datatables_1.10.19.jsJavascript Jquery Datatable-日期排序不适用于月份(相对于日期的月份),javascript,jquery,arrays,sorting,datatables,Javascript,Jquery,Arrays,Sorting,Datatables,数据表排序,包含除日期以外的所有内容。只使用datedays排序,不考虑其月份。 我有DD-MM-YYYY格式的日期,它是动态地从数据库中获取的。但有些日期也在另一个月之间 我使用了Jquery-3.3.1.js和Datatable datatables_1.10.19.js $(document).ready(function (){ var rows_selected = []; var bookid_value = []; var table = $('#examp
$(document).ready(function (){
var rows_selected = [];
var bookid_value = [];
var table = $('#example').DataTable({
"language": {
"search": ' ',
"searchPlaceholder": "Search",
},
lengthChange: false,
"scrollY": "1000px",
"scrollCollapse": true,
"paging": false,
'columnDefs': [{
'targets': 1,
'searchable': true,
'orderable': false,
'width': '1%',
'bSort': true,
"type": 'date'
}],
'order': [[1, 'asc']],
'rowCallback': function(row, data, dataIndex){
var rowId = data[0];
if($.inArray(rowId, rows_selected) !== -1){
$(row).find('input[type="checkbox"]').prop('checked', true);
$(row).addClass('selected');
}
}
});
});
输出:排序后
31-08-2019
31-07-2019
31-08-2019
25-07-2019
31-08-2019
08-07-2019
31-08-2019
04-07-2019
31-08-2019
10-07-2019
10-07-2019
13-07-2019
15-07-2019
31-08-2019
31-08-2019
尝试使用插件
可以找到更多信息据我所知,DataTable JS排序独立于您的查询。我使用JS共享我的解决方案。在我的例子中,第一列中的数字0是日期类型,默认情况下我要订购它 JavaScript
$('#datatable').DataTable({
order: [[0, 'desc']],
responsive: true
});
查看HTML示例
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.18/r-2.2.2/datatables.min.js"></script>
<table id="datatable" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Date</th>
<th>Name</th>
<th>Option</th>
</tr>
</thead>
<tbody>
<tr>
<td>datevalue</td>
<td>namevalue</td>
<td>optionvalue</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Date</th>
<th>Name</th>
<th>Option</th>
</tr>
</tfoot>
</table>
资料来源:
关于数据表无法识别您的日期格式。您可以在google上搜索datatable排序日期,您会发现:这些日期是作为字符串管理的,而不是日期。因此,此排序对于字符串是正确的。可能重复
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.18/r-2.2.2/datatables.min.js"></script>
<table id="datatable" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Date</th>
<th>Name</th>
<th>Option</th>
</tr>
</thead>
<tbody>
<tr>
<td>datevalue</td>
<td>namevalue</td>
<td>optionvalue</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Date</th>
<th>Name</th>
<th>Option</th>
</tr>
</tfoot>
</table>