mirror of
https://github.com/DataTables/DataTables.git
synced 2024-11-29 11:24:10 +01:00
Internal - altering how a draw is called
- Previously the master sort and filter functions would perform a draw, but this was a bit redundant, complex and didn't allow multiple changes to be queued up before a new draw was performed. The new API will allow this ability, so we need to allow it in the core as well. You can now do a sort, and it will be performed internally, but not actually drawn until the redraw function is called. This makes a full redraw much simpiler, and has the benefit that a standing redraw is now relatively trivial since it is all performed in a single place.
This commit is contained in:
parent
e014d9272f
commit
edfbf7491d
@ -718,6 +718,11 @@ this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseIns
|
||||
} );
|
||||
_fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
|
||||
}
|
||||
|
||||
// tmp hack during transition to new API
|
||||
oSettings._iDisplayStart = 0;
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
};
|
||||
|
||||
|
||||
@ -1163,7 +1168,7 @@ this.fnSort = function( aaSort )
|
||||
{
|
||||
var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
|
||||
oSettings.aaSorting = aaSort;
|
||||
_fnSort( oSettings );
|
||||
_fnReDraw( oSettings );
|
||||
};
|
||||
|
||||
|
||||
|
@ -496,25 +496,35 @@ function _fnDraw( oSettings )
|
||||
/**
|
||||
* Redraw the table - taking account of the various features which are enabled
|
||||
* @param {object} oSettings dataTables settings object
|
||||
* @param {boolean} [holdPosition] Keep the current paging position. By default
|
||||
* the paging is reset to the first page
|
||||
* @memberof DataTable#oApi
|
||||
*/
|
||||
function _fnReDraw( oSettings )
|
||||
function _fnReDraw( settings, holdPosition )
|
||||
{
|
||||
if ( oSettings.oFeatures.bSort )
|
||||
{
|
||||
/* Sorting will refilter and draw for us */
|
||||
_fnSort( oSettings, oSettings.oPreviousSearch );
|
||||
var
|
||||
features = settings.oFeatures,
|
||||
sort = features.bSort,
|
||||
filter = features.bFilter;
|
||||
|
||||
if ( sort ) {
|
||||
_fnSort( settings );
|
||||
}
|
||||
else if ( oSettings.oFeatures.bFilter )
|
||||
{
|
||||
/* Filtering will redraw for us */
|
||||
_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
|
||||
|
||||
if ( filter ) {
|
||||
_fnFilterComplete( settings, settings.oPreviousSearch );
|
||||
}
|
||||
else
|
||||
{
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
else {
|
||||
// No filtering, so we want to just use the display master
|
||||
settings.aiDisplay = settings.aiDisplayMaster.slice();
|
||||
}
|
||||
|
||||
if ( holdPosition === false ) {
|
||||
settings._iDisplayStart = 0;
|
||||
}
|
||||
|
||||
_fnCalculateEnd( settings );
|
||||
_fnDraw( settings );
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,6 +51,11 @@ function _fnFeatureHtmlFilter ( oSettings )
|
||||
"bSmart": oPreviousSearch.bSmart ,
|
||||
"bCaseInsensitive": oPreviousSearch.bCaseInsensitive
|
||||
} );
|
||||
|
||||
// Need to redraw, without resorting
|
||||
oSettings._iDisplayStart = 0;
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
}
|
||||
} );
|
||||
|
||||
@ -114,12 +119,6 @@ function _fnFilterComplete ( oSettings, oInput, iForce )
|
||||
oSettings.bFiltered = true;
|
||||
$(oSettings.oInstance).trigger('filter', oSettings);
|
||||
|
||||
/* Redraw the table */
|
||||
oSettings._iDisplayStart = 0;
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
|
||||
/* Rebuild search array 'offline' */
|
||||
_fnBuildSearchArray( oSettings, 0 );
|
||||
}
|
||||
|
||||
|
@ -48,20 +48,7 @@ function _fnInitialise ( oSettings )
|
||||
* drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows
|
||||
* the table to look initialised for Ajax sourcing data (show 'loading' message possibly)
|
||||
*/
|
||||
if ( oSettings.oFeatures.bSort )
|
||||
{
|
||||
_fnSort( oSettings );
|
||||
}
|
||||
else if ( oSettings.oFeatures.bFilter )
|
||||
{
|
||||
_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
|
||||
}
|
||||
else
|
||||
{
|
||||
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
}
|
||||
_fnReDraw( oSettings );
|
||||
|
||||
/* if there is an ajax source load the data */
|
||||
if ( (oSettings.sAjaxSource || oSettings.ajax) && !oSettings.oFeatures.bServerSide )
|
||||
@ -81,16 +68,7 @@ function _fnInitialise ( oSettings )
|
||||
*/
|
||||
oSettings.iInitDisplayStart = iAjaxStart;
|
||||
|
||||
if ( oSettings.oFeatures.bSort )
|
||||
{
|
||||
_fnSort( oSettings );
|
||||
}
|
||||
else
|
||||
{
|
||||
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
}
|
||||
_fnReDraw( oSettings );
|
||||
|
||||
_fnProcessingDisplay( oSettings, false );
|
||||
_fnInitComplete( oSettings, json );
|
||||
|
@ -103,7 +103,7 @@ function _fnPageChange ( settings, action )
|
||||
_fnLog( settings, 0, "Unknown paging action: "+action );
|
||||
}
|
||||
|
||||
var changed = settings._iDisplayStart === start;
|
||||
var changed = settings._iDisplayStart !== start;
|
||||
settings._iDisplayStart = start;
|
||||
|
||||
$(settings.oInstance).trigger('page', settings);
|
||||
|
@ -230,20 +230,6 @@ function _fnSort ( oSettings, bApplyClasses )
|
||||
/* Tell the draw function that we have sorted the data */
|
||||
oSettings.bSorted = true;
|
||||
$(oSettings.oInstance).trigger('sort', oSettings);
|
||||
|
||||
/* Copy the master data into the draw array and re-draw */
|
||||
if ( oSettings.oFeatures.bFilter )
|
||||
{
|
||||
/* _fnFilter() will redraw the table for us */
|
||||
_fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
|
||||
oSettings._iDisplayStart = 0; /* reset display back to page 0 */
|
||||
_fnCalculateEnd( oSettings );
|
||||
_fnDraw( oSettings );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -337,8 +323,8 @@ function _fnSortAttachListener ( oSettings, nNode, iDataIndex, fnCallback )
|
||||
}
|
||||
}
|
||||
|
||||
/* Run the sort */
|
||||
_fnSort( oSettings );
|
||||
/* Run the sort by calling a full redraw */
|
||||
_fnReDraw( oSettings );
|
||||
}; /* /fnInnerSorting */
|
||||
|
||||
if ( !oSettings.oFeatures.bProcessing )
|
||||
|
Loading…
Reference in New Issue
Block a user