【发布时间】:2015-10-12 08:09:36
【问题描述】:
我查看了this example,您可以在其中看到行索引正在显示,并且随着用户移动行而动态更新 - 这正是我所期望的行为。
但是,在该示例中,表格是通过静态 HTML 代码生成的。我正在使用来自 DataTable api 的 row.add() 方法。
为简单起见,我将向您展示一个示例,其中我通过一个简单的 for 循环添加行。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="../css/jquery.dataTables.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.js"></script>
<script src="../lib/jquery.dataTables.rowReordering.js"> </script>
<script>
$(function() {
$('#demo').html('<table cellpadding="0" cellspacing="0" border="0" class="display cell-border" id="example" ></table>');
t = $('#example').dataTable({
"columns":
[
{"title": "Action", "data": "action" },
],
}).rowReordering();;
for (var i = 0; i < 10; i ++)
{
t.api().row.add(
{
action: 'action'+String(i),
}).draw();
}
});
</script>
</head>
<body>
<div id="demo"> </div>
</body>
</html>
所以问题是:如何在表格中显示用户移动行时更新的行号?
【问题讨论】:
标签: jquery html datatables row html-table