提问人:Ashok rathod 提问时间:11/7/2023 更新时间:11/7/2023 访问量:17
使用 bStateSave: true 并使用 check and uncheck 列可见性时,dataTable 标头未正确更新(旧版本)
dataTable headers are not updated properly when using bStateSave: true and using check and uncheck column visibility(older version)
问:
var oTable = $('#table').dataTable( {
bProcessing: true,
sPaginationType: "full_numbers",
bServerSide: true,
bStateSave: true,
(............)
})
$('.toggle-vis').on('change', function () {
var columnIdx = $(this).data('column');
var column = oTable.fnSettings().aoColumns[columnIdx];
// Toggle the visibility
column.bVisible = this.checked;
var isChecked = column.bVisible;
$(this).prop('checked', isChecked);
// Update the header and cells associated with the column
var header = $('#crm_index_table thead th').eq(columnIdx);
var cells = $('#crm_index_table tbody td').filter(function (index) {
return index % oTable.fnSettings().aoColumns.length === columnIdx;
});
if (column.bVisible) {
header.show();
cells.show();
} else {
header.hide();
cells.hide();
}
oTable.fnDraw(false); // Redraw the table
});
上面的代码在单击复选框列列表后切换列可见性 请找到截图
默认情况下,候选“名称”和“操作”列处于选中状态,其他列处于选中状态,未选中选项。刷新页面并单击一个复选框后,DataTable 标题未正确更新。
答: 暂无答案
评论