我的数据表排序不正确。我认为问题与十进制值有关,因为它们不一致。 正确排序的最佳方法是什么? 我需要一个特殊的插件吗? 任何帮助/建议表示赞赏。 提前致谢。 请看下面的代码。非常感谢您的时间和帮助。
$(document).ready(function() {
$('#abc').DataTable( {
columnDefs: [
{ type: 'natural', targets: 0 }
],
responsive: true,
bSort: true,
order: []
} );
} );
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<meta charset=utf-8 />
<title>DataTables - JS Bin</title>
</head>
<body>
<table id="abc" style="width: 100%;"><thead>
<tr>
<th style=" width: 25%;">abcd</th>
</tr>
</thead><tbody>
<tr>
<td> 1.2</td>
<tr>
<td> 3.001</td>
</tr>
<tr>
<td> 8.1025</td>
</tr>
<tr>
<td> 40</td>
</tr>
<tr>
<td> 41</td>
</tr>
<tr>
<td> 180</td>
</tr>
<tr>
<td> 205</td>
</tr>
</tbody></table>
DataTables 默认是按文本排序。如果你想按数字排序,你需要在你的
columnDefs
中指定。
您可以将列类型设置为
num
,如下所述:
https://datatables.net/reference/option/columns.type
$(document).ready(function() {
$('#abc').DataTable({
columnDefs: [{
type: 'num',
targets: 0
}],
responsive: true,
bSort: true,
order: []
});
});