Skip to content

Commit 51f8599

Browse files
committed
Fix: Column visibility buttons could cause columns that shouldn't have had a control button (through the columns option) to show a control button if used with ColReorder.
- DD-626
1 parent d5ffe01 commit 51f8599

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

js/buttons.colVis.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ $.extend( DataTable.ext.buttons, {
108108
},
109109
init: function ( dt, button, conf ) {
110110
var that = this;
111+
button.attr( 'data-cv-idx', conf.columns );
111112

112113
dt
113114
.on( 'column-visibility.dt'+conf.namespace, function (e, settings) {
@@ -122,8 +123,17 @@ $.extend( DataTable.ext.buttons, {
122123
return;
123124
}
124125

125-
that.text( conf._columnText( dt, conf ) );
126-
that.active( dt.column( conf.columns ).visible() );
126+
conf.columns = $.inArray( conf.columns, details.mapping );
127+
button.attr( 'data-cv-idx', conf.columns );
128+
129+
// Reorder buttons for new table order
130+
button
131+
.parent()
132+
.children('[data-cv-idx]')
133+
.sort( function (a, b) {
134+
return (a.getAttribute('data-cv-idx')*1) - (b.getAttribute('data-cv-idx')*1);
135+
} )
136+
.appendTo(button.parent());
127137
} );
128138

129139
this.active( dt.column( conf.columns ).visible() );

0 commit comments

Comments
 (0)