From 08685a737c85b7aa4ccc3ef42e0f3d535cadbd91 Mon Sep 17 00:00:00 2001 From: KarloX2 <15713553+KarloX2@users.noreply.github.com> Date: Fri, 30 Nov 2018 10:35:31 +0100 Subject: [PATCH] Fixed column visibility buttons reordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the new 'data-cv-idx' attribute value was assigned from ´$.inArray( conf.columns, details.mapping )´. Instead ´details.mapping[conf.columns]´ is now used. Moreover, re-sorting the buttons is now only performed when the index really changed. --- js/buttons.colVis.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/js/buttons.colVis.js b/js/buttons.colVis.js index d5ec8de8..94d3eb49 100755 --- a/js/buttons.colVis.js +++ b/js/buttons.colVis.js @@ -123,17 +123,19 @@ $.extend( DataTable.ext.buttons, { return; } - conf.columns = $.inArray( conf.columns, details.mapping ); - button.attr( 'data-cv-idx', conf.columns ); - - // Reorder buttons for new table order - button - .parent() - .children('[data-cv-idx]') - .sort( function (a, b) { - return (a.getAttribute('data-cv-idx')*1) - (b.getAttribute('data-cv-idx')*1); - } ) - .appendTo(button.parent()); + if (conf.columns !== details.mapping[conf.columns]) { + conf.columns = details.mapping[conf.columns]; + button.attr('data-cv-idx', conf.columns); + + // Reorder buttons for new table order + button + .parent() + .children('[data-cv-idx]') + .sort(function (a, b) { + return (a.getAttribute('data-cv-idx') * 1) - (b.getAttribute('data-cv-idx') * 1); + }) + .appendTo(button.parent()); + } } ); this.active( dt.column( conf.columns ).visible() );