gpt4 book ai didi

javascript - jQuery DataTables 排序不起作用

转载 作者:行者123 更新时间:2023-12-02 16:24:02 26 4
gpt4 key购买 nike

使用 jQuery 2.1.3 和 DataTables 1.10.5,当我单击列上方的向上和向下箭头时,我的表不会排序。据我从文档中可以看出,这是最简单的示例,并且应该可行。我似乎无法弄清楚为什么不是。

我的 HTML/JavaScript

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<title>Simple Example</title>

<link rel="stylesheet" media="screen" href="/assets/css/bootstrap.min.css">
<link rel="stylesheet" media="screen" href="/assets/css/bootstrap-theme.min.css">
<link rel="stylesheet" media="screen" href="/assets/css/jquery.dataTables.css">
</head>
<body>
<table id="table-guid" class="display compact" cellspacing="0" width="100%">
<thead>
<tr>
<th>Column-1</th>
<th>Column-2</th>
<th>Column-3</th>
</tr>
</thead>

<tfoot>
<tr>
<th>Column-1</th>
<th>Column-2</th>
<th>Column-3</th>
</tr>
</tfoot>
<tbody>
<tr id="A">
<td>A-1</td>
<td>A-2</td>
<td>A-3</td>
</tr>
<tr id="B">
<td>B-1</td>
<td>B-2</td>
<td>B-3</td>
</tr>
<tr id="C">
<td>C-1</td>
<td>C-2</td>
<td>C-3</td>
</tr>
</tbody>
</table>

<script src="/assets/js/jquery-2.1.3.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function ()
{
var table = $('#table-guid').DataTable();
});
</script>
</body>
</html>

最佳答案

您必须定义列数据的类型。这里的问题似乎来自连字符,它正在工作 without it

解决方案:JsFiddle

$('#table-guid').dataTable( {
"columnDefs": [
{ "type": "numeric-comma", targets: "_all" }
]
});

这是documentation

关于javascript - jQuery DataTables 排序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28862456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com