【发布时间】:2016-05-12 20:34:17
【问题描述】:
你好,我有一个按钮,点击时会从数据表中删除一行,然后重绘自身。我试过this,但它在删除行时将我的数据表恢复为默认设置:
var tbl;
$(document).ready(function() {
tbl = $('#myTable').DataTable({
"bLengthChange": false,
"bFilter": false,
"iDisplayLength": 5,
"columns": [{
"width": "50%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}],
"responsive": true,
"retrieve": true
});
});
function delete()
tbl.rows($(this).parents('tr')).remove().draw();
}
我也试过了,结果是一样的:
function delete()
$('#myTable').DataTable().rows($(this).parents('tr')).remove().draw();
}
我还尝试在表格中包含reinitializing,但出现错误
function delete() {
var tbl = $('#myTable').DataTable({
"bLengthChange": false,
"bFilter": false,
"iDisplayLength": 5,
"columns": [{
"width": "50%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}],
"responsive": true,
"retrieve": true
});
tbl.rows($(this).parents('tr')).remove().draw();
}
这样做的正确方法是什么?
【问题讨论】:
-
你需要指出
row要删除,this在这种情况下不引用元素。
标签: javascript jquery html css datatable