7
if ( typeof define === 'function' && define.amd ) {
9
define( ['jquery', 'datatables.net', 'datatables.net-buttons'], function ( $ ) {
10
return factory( $, window, document );
13
else if ( typeof exports === 'object' ) {
15
module.exports = function (root, $) {
20
if ( ! $ || ! $.fn.dataTable ) {
21
$ = require('datatables.net')(root, $).$;
24
if ( ! $.fn.dataTable.Buttons ) {
25
require('datatables.net-buttons')(root, $);
28
return factory( $, root, root.document );
33
factory( jQuery, window, document );
35
}(function( $, window, document, undefined ) {
37
var DataTable = $.fn.dataTable;
40
$.extend( DataTable.ext.buttons, {
42
colvis: function ( dt, conf ) {
46
init: function ( dt, n ) {
49
text: function ( dt ) {
50
return dt.i18n( 'buttons.colvis', 'Column visibility' );
52
className: 'buttons-colvis',
55
extend: 'columnsToggle',
56
columns: conf.columns,
57
columnText: conf.columnText
62
dt.on( 'column-reorder.dt'+conf.namespace, function (e, settings, details) {
65
dt.button(null, dt.button(null, node).node()).collectionRebuild([{
66
extend: 'columnsToggle',
67
columns: conf.columns,
68
columnText: conf.columnText
76
columnsToggle: function ( dt, conf ) {
77
var columns = dt.columns( conf.columns ).indexes().map( function ( idx ) {
79
extend: 'columnToggle',
81
columnText: conf.columnText
89
columnToggle: function ( dt, conf ) {
91
extend: 'columnVisibility',
92
columns: conf.columns,
93
columnText: conf.columnText
98
columnsVisibility: function ( dt, conf ) {
99
var columns = dt.columns( conf.columns ).indexes().map( function ( idx ) {
101
extend: 'columnVisibility',
103
visibility: conf.visibility,
104
columnText: conf.columnText
114
text: function ( dt, button, conf ) {
115
return conf._columnText( dt, conf );
117
className: 'buttons-columnVisibility',
118
action: function ( e, dt, button, conf ) {
119
var col = dt.columns( conf.columns );
120
var curr = col.visible();
122
col.visible( conf.visibility !== undefined ?
124
! (curr.length ? curr[0] : false )
127
init: function ( dt, button, conf ) {
129
button.attr( 'data-cv-idx', conf.columns );
132
.on( 'column-visibility.dt'+conf.namespace, function (e, settings) {
133
if ( ! settings.bDestroying && settings.nTable == dt.settings()[0].nTable ) {
134
that.active( dt.column( conf.columns ).visible() );
137
.on( 'column-reorder.dt'+conf.namespace, function (e, settings, details) {
139
if ( conf.destroying ) {
143
if ( dt.columns( conf.columns ).count() !== 1 ) {
149
that.text( conf._columnText( dt, conf ) );
152
that.active( dt.column( conf.columns ).visible() );
155
this.active( dt.column( conf.columns ).visible() );
157
destroy: function ( dt, button, conf ) {
159
.off( 'column-visibility.dt'+conf.namespace )
160
.off( 'column-reorder.dt'+conf.namespace );
163
_columnText: function ( dt, conf ) {
168
var idx = dt.column( conf.columns ).index();
169
var title = dt.settings()[0].aoColumns[ idx ].sTitle;
172
title = dt.column(idx).header().innerHTML;
177
.replace(/<br\s*\/?>/gi, " ")
178
.replace(/<select(.*?)<\/select>/g, "")
179
.replace(/<!\-\-.*?\-\->/g, "")
180
.replace(/<.*?>/g, "")
181
.replace(/^\s+|\s+$/g,"");
183
return conf.columnText ?
184
conf.columnText( dt, idx, title ) :
191
className: 'buttons-colvisRestore',
193
text: function ( dt ) {
194
return dt.i18n( 'buttons.colvisRestore', 'Restore visibility' );
197
init: function ( dt, button, conf ) {
198
conf._visOriginal = dt.columns().indexes().map( function ( idx ) {
199
return dt.column( idx ).visible();
203
action: function ( e, dt, button, conf ) {
204
dt.columns().every( function ( i ) {
207
var idx = dt.colReorder && dt.colReorder.transpose ?
208
dt.colReorder.transpose( i, 'toOriginal' ) :
211
this.visible( conf._visOriginal[ idx ] );
218
className: 'buttons-colvisGroup',
220
action: function ( e, dt, button, conf ) {
221
dt.columns( conf.show ).visible( true, false );
222
dt.columns( conf.hide ).visible( false, false );
234
return DataTable.Buttons;