diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 0c20e41d..d0e4b946 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -81fd129ec8639d8898da77b20c3bc711a9376e5d +3a3d513eb3bee21daa9318ffd742c185bc9821a0 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 0e060a7d..3060b1a2 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -4046,6 +4046,73 @@ } + /** + * Function to run on user sort request + * @param {object} settings dataTables settings object + * @param {node} attachTo node to attach the handler to + * @param {int} colIdx column sorting index + * @param {boolean} [append=false] Append the requested sort to the existing + * sort if true (i.e. multi-column sort) + * @param {function} [callback] callback function + * @memberof DataTable#oApi + */ + function _fnSortListener ( settings, colIdx, append, callback ) + { + var col = settings.aoColumns[ colIdx ]; + var sorting = settings.aaSorting; + var asSorting = col.asSorting; + var nextSortIdx; + var next = function ( a ) { + var idx = a._idx; + if ( idx === undefined ) { + idx = $.inArray( a[1], asSorting ); + } + + return idx+1 >= asSorting.length ? 0 : idx+1; + }; + + // If appending the sort then we are multi-column sorting + if ( append && settings.oFeatures.bSortMulti ) { + // Are we already doing some kind of sort on this column? + var sortIdx = $.inArray( colIdx, _pluck(sorting, '0') ); + + if ( sortIdx !== -1 ) { + // Yes, modify the sort + nextSortIdx = next( sorting[sortIdx] ); + + sorting[sortIdx][1] = asSorting[ nextSortIdx ]; + sorting[sortIdx]._idx = nextSortIdx; + } + else { + // No sort on this column yet + sorting.push( [ colIdx, asSorting[0], 0 ] ); + sorting[sorting.length-1]._idx = 0; + } + } + else if ( sorting[0][0] == colIdx ) { + // Single column - already sorting on this column, modify the sort + nextSortIdx = next( sorting[0] ); + + sorting[0][1] = asSorting[ nextSortIdx ]; + sorting[0]._idx = nextSortIdx; + } + else { + // Single column - sort only on this column + sorting.length = 0; + sorting.push( [ colIdx, asSorting[0] ] ); + sorting[0]._idx = 0; + } + + // Run the sort by calling a full redraw + _fnReDraw( settings ); + + // callback used for async user interaction + if ( typeof callback == 'function' ) { + callback( settings ); + } + } + + /** * Attach a sort handler (click) to a node * @param {object} settings dataTables settings object @@ -4057,8 +4124,6 @@ function _fnSortAttachListener ( settings, attachTo, colIdx, callback ) { var col = settings.aoColumns[ colIdx ]; - var sorting = settings.aaSorting; - var asSorting = col.asSorting; _fnBindAction( attachTo, {}, function (e) { /* If the column is not sortable - don't to anything */ @@ -4070,68 +4135,9 @@ // Use a timeout to allow the processing display to be shown. setTimeout( function() { - var nextSort; - - // If the shift key is pressed then we are multiple column sorting - if ( e.shiftKey && settings.oFeatures.bSortMulti ) { - // Are we already doing some kind of sort on this column? - var curr = _pluck( sorting, '0' ); - var idx = $.inArray( colIdx, curr ); - - if ( idx !== -1 ) { - // Yes, modify the sort - if ( sorting[idx][0] == colIdx ) { - nextSort = sorting[idx][2] + 1; - - if ( ! asSorting[ nextSort ] ) { - // Reached the end of the sorting options, remove from multi-col sort - sorting.splice( idx, 1 ); - } - else { - // Move onto next sorting direction - sorting[idx][1] = asSorting[ nextSort ]; - sorting[idx][2] = nextSort; - } - } - } - else { - // No sort on this column yet - sorting.push( [ colIdx, asSorting[0], 0 ] ); - } - } - else - { - // If no shift key then single column sort - if ( sorting.length == 1 && sorting[0][0] == colIdx ) { - // Already sorting on this column, modify the sort - nextSort = sorting[0][2] + 1; - - if ( ! asSorting[ nextSort ] ) { - nextSort = 0; - } - - sorting[0][1] = asSorting[ nextSort ]; - sorting[0][2] = nextSort; - } - else { - // Sort only on this column - sorting.length = 0; - sorting.push( [ colIdx, asSorting[0], 0 ] ); - } - } - - // Run the sort by calling a full redraw - _fnReDraw( settings ); - - if ( !settings.oFeatures.bServerSide ) { - _fnProcessingDisplay( settings, false ); - } + _fnSortListener( settings, colIdx, e.shiftKey, callback ); + _fnProcessingDisplay( settings, false ); }, 0 ); - - // callback used for async user interaction - if ( typeof callback == 'function' ) { - callback( settings ); - } } ); } @@ -4256,6 +4262,9 @@ */ function _fnLoadState ( oSettings, oInit ) { + var i, ien; + var columns = oSettings.aoColumns; + if ( !oSettings.oFeatures.bStateSave ) { return; @@ -4282,7 +4291,7 @@ } // Number of columns have changed - all bets are off, no restore of settings - if ( oSettings.aoColumns.length !== oData.aoSearchCols.length ) { + if ( columns.length !== oData.aoSearchCols.length ) { return; } @@ -4293,15 +4302,17 @@ oSettings._iDisplayStart = oData.iStart; oSettings.iInitDisplayStart = oData.iStart; oSettings._iDisplayLength = oData.iLength; - oSettings.aaSorting = oData.aaSorting.slice(); + oSettings.aaSorting = $.map( oData.aaSorting, function (d) { + return d[0] >= columns.length ? [ 0, columns[i].asSorting[0] ] : d; + } ); /* Search filtering */ $.extend( oSettings.oPreviousSearch, oData.oSearch ); $.extend( true, oSettings.aoPreSearchCols, oData.aoSearchCols ); /* Column visibility state */ - for ( var i=0 ; i= oSettings.aoColumns.length ) + for ( i=0, iLen=oSettings.aaSorting.length ; i *
  • Index 0 - column number
  • *
  • Index 1 - current sorting direction
  • - *
  • Index 2 - index of asSorting for this column
  • * * Note that this parameter will be set by the initialisation routine. To * set a default use {@link DataTable.defaults}.