一组按钮切换单个列的可见性
注意:这个需要使用Bottons扩展
这是一组按钮,自动生成相同标题的文本列,可以用来切换列的可见性
The
columnsToggleButton
button type differs from the
colvisButton
type in that it
does not extend the
collectionButton
type
(although it could be assigned to a collection's buttons attribute if you wished).
The buttons for each column are automatically expanded where this button is included.
这个按钮有以下选项配置:
名称 | 默认 |
---|---|
columns |
undefined |
Columns selector that defines the columns to include in the column visibility button set.
By default this is
undefinedType
which results in all columns being selected,
but any of the
column-selectorType
options can be used to define a custom button set.
|
|
visibility |
undefined |
用来给选中的列设置值,true 为显示, false 为隐藏,
undefined 为切换当前状态
|
Datatables初始化:显示每一列的按钮
$('#myTable').DataTable( { buttons: [ 'columnsToggle' ] } );
Datatables初始化:只显示class名为toggle的按钮
$('#myTable').DataTable( { buttons: [ { extend: 'columnsToggle', columns: '.toggle' } ] } );
直接初始化:在集合中显示每一列的按钮 ,和 colvis
按钮是一样的
new $.fn.dataTable.Buttons( table, { buttons: [ { extend: 'collection', buttons: [ 'columnsToggle' ] } ] } );
Translation from DataTables.net, with permission