如何动态隐藏或显示使用 javascript 中的数据 table 和 javascript 源创建的 table 列?

How to hide or show dynamically column of table created using datatables in javascript with javascript source?

当数据表的来源是 javascript 时,您知道如何 dynamically/later 隐藏或显示列吗?

此方法适用于使用 html 源创建的表,但不适用于使用 javascript 源创建的表?

 var table = $('#example').dataTable({
  "data": source,
  "columns": columns,
  "columnDefs": [
  {
    "targets": [ 0 ],
    "visible": false, // no worries for hiding column at start 
  });
    var col = table.column("1").visible(false); //error if source is javascript

我终于发现我们可以这样做:

 table.fnSetColumnVis(3, false);

当 table 使用方法 datatable(旧版本)创建时有效

尽管 column() 使用方法 Datatable(新版本)

创建 table 时仍会出现问题