Skip to content

Commit

Permalink
Sync tag release - 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanJard committed Jan 14, 2022
1 parent f5d685e commit c03cdd3
Show file tree
Hide file tree
Showing 13 changed files with 588 additions and 1,609 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"types/types.d.ts"
],
"src-repo": "http://github.com/DataTables/Buttons",
"last-tag": "2.1.1",
"last-tag": "2.2.0",
"last-sync": "097b129bcdedbb65f2c267538cb831515911615c"
}
53 changes: 12 additions & 41 deletions js/buttons.colVis.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,18 @@ var DataTable = $.fn.dataTable;
$.extend( DataTable.ext.buttons, {
// A collection of column visibility buttons
colvis: function ( dt, conf ) {
var node = null;
var buttonConf = {
return {
extend: 'collection',
init: function ( dt, n ) {
node = n;
},
text: function ( dt ) {
return dt.i18n( 'buttons.colvis', 'Column visibility' );
},
className: 'buttons-colvis',
closeButton: false,
buttons: [ {
extend: 'columnsToggle',
columns: conf.columns,
columnText: conf.columnText
} ]
};

// Rebuild the collection with the new column structure if columns are reordered
dt.on( 'column-reorder.dt'+conf.namespace, function (e, settings, details) {
// console.log(node);
// console.log('node', dt.button(null, node).node());
dt.button(null, dt.button(null, node).node()).collectionRebuild([{
extend: 'columnsToggle',
columns: conf.columns,
columnText: conf.columnText
}]);
});

return buttonConf;
},

// Selected columns with individual buttons - toggle column visibility
Expand Down Expand Up @@ -126,30 +108,28 @@ $.extend( DataTable.ext.buttons, {
},
init: function ( dt, button, conf ) {
var that = this;
button.attr( 'data-cv-idx', conf.columns );

dt
.on( 'column-visibility.dt'+conf.namespace, function (e, settings) {
if ( ! settings.bDestroying && settings.nTable == dt.settings()[0].nTable ) {
if ( ! settings.bDestroying ) {
that.active( dt.column( conf.columns ).visible() );
}
} )
.on( 'column-reorder.dt'+conf.namespace, function (e, settings, details) {
// Button has been removed from the DOM
if ( conf.destroying ) {
// Don't rename buttons based on column name if the button
// controls more than one column!
if ( dt.columns( conf.columns ).count() !== 1 ) {
return;
}

if ( dt.columns( conf.columns ).count() !== 1 ) {
return;
if ( typeof conf.columns === 'number' ) {
conf.columns = details.mapping[ conf.columns ];
}

// This button controls the same column index but the text for the column has
// changed
that.text( conf._columnText( dt, conf ) );
var col = dt.column( conf.columns );

// Since its a different column, we need to check its visibility
that.active( dt.column( conf.columns ).visible() );
that.text( conf._columnText( dt, conf ) );
that.active( col.visible() );
} );

this.active( dt.column( conf.columns ).visible() );
Expand All @@ -166,18 +146,9 @@ $.extend( DataTable.ext.buttons, {
// `$( column(col).node() ).text()` but the node might not have been
// populated when Buttons is constructed.
var idx = dt.column( conf.columns ).index();
var title = dt.settings()[0].aoColumns[ idx ].sTitle;

if (! title) {
title = dt.column(idx).header().innerHTML;
}

title = title
var title = dt.settings()[0].aoColumns[ idx ].sTitle
.replace(/\n/g," ") // remove new lines
.replace(/<br\s*\/?>/gi, " ") // replace line breaks with spaces
.replace(/<select(.*?)<\/select>/g, "") // remove select tags, including options text
.replace(/<!\-\-.*?\-\->/g, "") // strip HTML comments
.replace(/<.*?>/g, "") // strip HTML
.replace( /<.*?>/g, "" ) // strip HTML
.replace(/^\s+|\s+$/g,""); // trim

return conf.columnText ?
Expand Down
12 changes: 6 additions & 6 deletions js/buttons.colVis.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c03cdd3

Please sign in to comment.