1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-01 13:24:10 +01:00

Build: Usage for the make script

This commit is contained in:
Allan Jardine 2013-07-22 15:28:06 +01:00
parent 381f60858e
commit 572e0ca9b9
2 changed files with 85 additions and 96 deletions

View File

@ -1 +1 @@
81fd129ec8639d8898da77b20c3bc711a9376e5d 3a3d513eb3bee21daa9318ffd742c185bc9821a0

View File

@ -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 * Attach a sort handler (click) to a node
* @param {object} settings dataTables settings object * @param {object} settings dataTables settings object
@ -4057,8 +4124,6 @@
function _fnSortAttachListener ( settings, attachTo, colIdx, callback ) function _fnSortAttachListener ( settings, attachTo, colIdx, callback )
{ {
var col = settings.aoColumns[ colIdx ]; var col = settings.aoColumns[ colIdx ];
var sorting = settings.aaSorting;
var asSorting = col.asSorting;
_fnBindAction( attachTo, {}, function (e) { _fnBindAction( attachTo, {}, function (e) {
/* If the column is not sortable - don't to anything */ /* 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. // Use a timeout to allow the processing display to be shown.
setTimeout( function() { setTimeout( function() {
var nextSort; _fnSortListener( settings, colIdx, e.shiftKey, callback );
// 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 ); _fnProcessingDisplay( settings, false );
}
}, 0 ); }, 0 );
// callback used for async user interaction
if ( typeof callback == 'function' ) {
callback( settings );
}
} ); } );
} }
@ -4256,6 +4262,9 @@
*/ */
function _fnLoadState ( oSettings, oInit ) function _fnLoadState ( oSettings, oInit )
{ {
var i, ien;
var columns = oSettings.aoColumns;
if ( !oSettings.oFeatures.bStateSave ) if ( !oSettings.oFeatures.bStateSave )
{ {
return; return;
@ -4282,7 +4291,7 @@
} }
// Number of columns have changed - all bets are off, no restore of settings // 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; return;
} }
@ -4293,15 +4302,17 @@
oSettings._iDisplayStart = oData.iStart; oSettings._iDisplayStart = oData.iStart;
oSettings.iInitDisplayStart = oData.iStart; oSettings.iInitDisplayStart = oData.iStart;
oSettings._iDisplayLength = oData.iLength; 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 */ /* Search filtering */
$.extend( oSettings.oPreviousSearch, oData.oSearch ); $.extend( oSettings.oPreviousSearch, oData.oSearch );
$.extend( true, oSettings.aoPreSearchCols, oData.aoSearchCols ); $.extend( true, oSettings.aoPreSearchCols, oData.aoSearchCols );
/* Column visibility state */ /* Column visibility state */
for ( var i=0 ; i<oData.abVisCols.length ; i++ ) { for ( i=0, ien=oData.abVisCols.length ; i<ien ; i++ ) {
oSettings.aoColumns[i].bVisible = oData.abVisCols[i]; columns[i].bVisible = oData.abVisCols[i];
} }
_fnCallbackFire( oSettings, 'aoStateLoaded', 'stateLoaded', [oSettings, oData] ); _fnCallbackFire( oSettings, 'aoStateLoaded', 'stateLoaded', [oSettings, oData] );
@ -5757,37 +5768,16 @@
/* /*
* Sorting * Sorting
* Check the aaSorting array
* @todo For modularisation (1.11) this needs to do into a sort start up handler * @todo For modularisation (1.11) this needs to do into a sort start up handler
*/ */
for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
{
if ( oSettings.aaSorting[i][0] >= oSettings.aoColumns.length )
{
oSettings.aaSorting[i][0] = 0;
}
var oColumn = oSettings.aoColumns[ oSettings.aaSorting[i][0] ];
/* Add a default sorting index */ // If aaSorting is not defined, then we use the first indicator in asSorting
if ( oSettings.aaSorting[i][2] === undefined ) // in case that has been altered, so the default sort reflects that option
{
oSettings.aaSorting[i][2] = 0;
}
/* If aaSorting is not defined, then we use the first indicator in asSorting */
if ( oInit.aaSorting === undefined ) if ( oInit.aaSorting === undefined )
{ {
oSettings.aaSorting[i][1] = oColumn.asSorting[0]; for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
}
/* Set the current sorting index based on aoColumns.asSorting */
for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ )
{ {
if ( oSettings.aaSorting[i][1] == oColumn.asSorting[j] ) oSettings.aaSorting[i][1] = oSettings.aoColumns[ i ].asSorting[0];
{
oSettings.aaSorting[i][2] = j;
break;
}
} }
} }
@ -12623,7 +12613,6 @@
* <ul> * <ul>
* <li>Index 0 - column number</li> * <li>Index 0 - column number</li>
* <li>Index 1 - current sorting direction</li> * <li>Index 1 - current sorting direction</li>
* <li>Index 2 - index of asSorting for this column</li>
* </ul> * </ul>
* Note that this parameter will be set by the initialisation routine. To * Note that this parameter will be set by the initialisation routine. To
* set a default use {@link DataTable.defaults}. * set a default use {@link DataTable.defaults}.