From 14f5f630c92c6d12bb74ff56f8a3d0d3b18d236c Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Thu, 28 Aug 2014 14:24:16 +0100 Subject: [PATCH] Fix: Could not remove a multi-column sort using shift click like you could in 1.9- This fixes DataTables/DataTables #391 --- .datatables-commit-sync | 2 +- media/js/jquery.dataTables.js | 25 +++++++++++++++++++------ media/js/jquery.dataTables.min.js | 18 +++++++++--------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index b6e2abcf..ff758831 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -91ad2d1c4a8a461282aa0b07dd636c39c6cf18d1 +f75bfb143b4b44d3f9b83fb1a499c2bd35da9e10 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 60b8bad6..f8c27b4c 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -4409,11 +4409,15 @@ iCol = aDataSort[k]; sType = aoColumns[ iCol ].sType || 'string'; + if ( nestedSort[i]._idx === undefined ) { + nestedSort[i]._idx = $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting ); + } + aSort.push( { src: srcCol, col: iCol, dir: nestedSort[i][1], - index: $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting ), + index: nestedSort[i]._idx, type: sType, formatter: DataTable.ext.type.order[ sType+"-pre" ] } ); @@ -4616,13 +4620,17 @@ var sorting = settings.aaSorting; var asSorting = col.asSorting; var nextSortIdx; - var next = function ( a ) { + var next = function ( a, overflow ) { var idx = a._idx; if ( idx === undefined ) { idx = $.inArray( a[1], asSorting ); } - return idx+1 >= asSorting.length ? 0 : idx+1; + return idx+1 < asSorting.length ? + idx+1 : + overflow ? + null : + 0; }; // Convert to 2D array if needed @@ -4637,10 +4645,15 @@ if ( sortIdx !== -1 ) { // Yes, modify the sort - nextSortIdx = next( sorting[sortIdx] ); + nextSortIdx = next( sorting[sortIdx], true ); - sorting[sortIdx][1] = asSorting[ nextSortIdx ]; - sorting[sortIdx]._idx = nextSortIdx; + if ( nextSortIdx === null ) { + sorting.splice( sortIdx, 1 ); + } + else { + sorting[sortIdx][1] = asSorting[ nextSortIdx ]; + sorting[sortIdx]._idx = nextSortIdx; + } } else { // No sort on this column yet diff --git a/media/js/jquery.dataTables.min.js b/media/js/jquery.dataTables.min.js index 24436aee..61abeaa7 100644 --- a/media/js/jquery.dataTables.min.js +++ b/media/js/jquery.dataTables.min.js @@ -41,7 +41,7 @@ g;0!==p.ext.search.length&&(c=!0);g=xb(a);if(0>=b.length)a.aiDisplay=f.slice();e a.aoColumns,c,d,e,f,g,j,i,h,m=p.ext.type.search;c=!1;d=0;for(f=a.aoData.length;d",{"class":a.oClasses.sInfo,id:!c?b+"_info":null});c||(a.aoDrawCallback.push({fn:Ab,sName:"information"}),d.attr("role","status").attr("aria-live","polite"),h(a.nTable).attr("aria-describedby",b+"_info"));return d[0]}function Ab(a){var b=a.aanFeatures.i;if(0!==b.length){var c= a.oLanguage,d=a._iDisplayStart+1,e=a.fnDisplayEnd(),f=a.fnRecordsTotal(),g=a.fnRecordsDisplay(),j=g?c.sInfo:c.sInfoEmpty;g!==f&&(j+=" "+c.sInfoFiltered);j+=c.sInfoPostFix;j=Bb(a,j);c=c.fnInfoCallback;null!==c&&(j=c.call(a.oInstance,a,d,e,f,g,j));h(b).html(j)}}function Bb(a,b){var c=a.fnFormatNumber,d=a._iDisplayStart+1,e=a._iDisplayLength,f=a.fnRecordsDisplay(),g=-1===e;return b.replace(/_START_/g,c.call(a,d)).replace(/_END_/g,c.call(a,a.fnDisplayEnd())).replace(/_MAX_/g,c.call(a,a.fnRecordsTotal())).replace(/_TOTAL_/g, -c.call(a,f)).replace(/_PAGE_/g,c.call(a,g?1:Math.ceil(d/e))).replace(/_PAGES_/g,c.call(a,g?1:Math.ceil(f/e)))}function ra(a){var b,c,d=a.iInitDisplayStart,e=a.aoColumns,f;c=a.oFeatures;if(a.bInitialised){lb(a);ib(a);ba(a,a.aoHeader);ba(a,a.aoFooter);B(a,!0);c.bAutoWidth&&Ca(a);b=0;for(c=e.length;b",{name:c+"_length","aria-controls":c,"class":b.sLengthSelect}),g=0,j=f.length;g