【发布时间】:2015-11-05 09:20:03
【问题描述】:
在 Jquery Datatable 中,我尝试动态添加行。它是动态添加的,但它没有添加到表格的顶部。
谁能帮我使用 Jquery Datatable 在表格顶部动态添加行。
这是小提琴http://jsfiddle.net/inDiscover/yo83k3z9/
内联代码
<!DOCTYPE html>
<html>
<head>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
var giCount = 1;
jQuery(document).ready( function () {
jQuery('#table_id').DataTable();
} );
function fnClickAddRow() {
jQuery('#table_id').dataTable().fnAddData( [
giCount+".1",
giCount+".2",
] );
giCount++;
}
</script>
</head>
<body>
<a onClick="fnClickAddRow()">Add Row</a>
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
【问题讨论】:
-
要了解如何在某个索引处插入一行,作为位置#1,请参见 -> stackoverflow.com/questions/30712227/…
标签: jquery datatables