一键重置列重新排序和 colvis

Reset column reorder and colvis in one button

我正在使用 Datatables Jquery 库并使用 ColReorder 和 Colvis 功能。目前有一种方法可以重置列重新排序,即

table.colReorder.reset();

colvis reset是通过在设置中添加"Show All"来完成的,像这样

 colVis = {
    showAll: "Restore Defaults"
};

有没有办法,我可以将这两个功能结合到一个单击按钮中?例如:

$("#restore_defaults").click(function(){
   // reset colorder
//reset column visibility
}

重置 ColReorder 很简单。但是没有 public API 来更改 ColVis 的可见性。

// this is to reset ColReorder
table.colReorder.reset();

实施列可见性:

Change visibility of each column manually and use fnRebuild 重新呈现 ColVis 下拉列表中的复选框,因为可见性已更改,复选框也应如此。

// change visibility of columns
table.columns().visible( true, true );
// re-render the buttons in ColVis button dropdown
$.fn.dataTable.ColVis.fnRebuild( table );

这是一个演示 http://jsfiddle.net/dhirajbodicherla/189Lp6u6/24/