[英]DataTable (jQuery) remove last child
我有以下问题:我有一个按第一列降序排列的DataTable(jQuery)。 我要尝试执行的操作是,如果已达到计数(例如10),则删除最后一行,因此表永远不会超过10行。 我尝试了几种方法都没有成功。 任何帮助,将不胜感激。
更新:由于某种原因,它仅删除第一行。
// This is where I assign the DataTable to a variable.
var unprintedTable = $('#unprinted-table').DataTable({
"order": [
[1, "desc"]
]
});
var unprintedLogLength = 5;
var unprintedLogCount = 0; // Incremented when a new row is added.
if (unprintedLogCount > unprintedLogLength) {
unprintedTable.row($(this).parent('tr:last-child')[0]).remove();
}
试试这个
<button onclick="RemoveLastRow()">Remove Last Row</button>
<table id="MyTable" class="table table-bordered table-striped" width="100%" cellspacing="0">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td><button class="Mybtn">Click me</button></td>
<td>Hello</td>
</tr>
</tbody>
</table>
<script>
var Dtable;
$(document).ready(function () {
Dtable = $("#MyTable").DataTable();
});
function RemoveLastRow() {
Dtable.row(Dtable.data().length).remove().draw(false);
);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.