[columnDefs
用于将列类型设置为“日期”时,排序将中断,但仅在Edge中。 Firefox和Chrome继续表现正常。
不会引发任何错误,如果我删除该类型,它将重新启用以字母数字形式排序。
任何人都可以告知发生这种情况的原因以及如何解决吗?
以下精确的可复制示例:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
</head>
<body>
<table id='target'>
<thead>
<tr>
<th>Foo</th>
<th width='200'>date</th>
<th>bar</th>
</tr>
</thead>
</table>
<script>
console.log('script start');
$('#target').DataTable({
'pageLength': 100,
'lengthMenu': [100, 150, 200],
'data': [
['aaa', '30-Nov-2020', 'ccc'],
['aaa', '03-Nov-2020', 'ccc'],
['aaa', '31-Oct-2020', 'ccc'],
['aaa', '30-Oct-2020', 'ccc'],
['aaa', '06-Oct-2020', 'ccc'],
['aaa', '30-Sep-2020', 'ccc'],
['aaa', '30-Sep-2020', 'ccc'],
['aaa', '15-Sep-2020', 'ccc']
],
"columnDefs": [
{
"targets": 1,
"type": "date"
}
]
});
</script>
</body>
</html>
如果问题仍然存在,那么您也可以参考此示例,该示例在MS Edge浏览器中运行正常。