我有一个数据表,并且在“th”处有垃圾桶图标。单击垃圾桶图标时,我需要删除整个列(需要从所有页面中删除所有数据)。我尝试了以下代码,但在分页下不起作用。请帮助我...
$(document).on("click", ".a_datatbl_trash", function (e)
{
var indexToRemove = $(this).parent().index();
$("#datatable-buttons tbody tr").each(function() {
$(this).find("td:eq("+indexToRemove+")").remove();
});
$(this).closest("th").remove();
)};
Run Code Online (Sandbox Code Playgroud)
这是html结构
<thead>
<tr role="row">
<th class="sorting_asc" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Article title: activate to sort column descending">Article title
<a href="" class="dragtable-drag-handle" style="background: none; width: 15px;"><i class="fa fa-fw fa-arrows"></i></a>
<a href="" class="a_datatbl_trash" style="float: right;"><i class="fa fa-fw fa-trash datatbl_trash" style="float: right;"></i></a>
</th>
</tr>
</thead>
Run Code Online (Sandbox Code Playgroud)
为什么不使用可见的 API?它不适合您的需要吗?这可能是这样的:
yourDatatable.column(columnIndex).visible(false);
Run Code Online (Sandbox Code Playgroud)
或者你先去销毁数据然后更新。
| 归档时间: |
|
| 查看次数: |
6042 次 |
| 最近记录: |