mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-17 15:54:14 +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 );
|
_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] );
|
var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
|
||||||
oSettings.aaSorting = aaSort;
|
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
|
* Redraw the table - taking account of the various features which are enabled
|
||||||
* @param {object} oSettings dataTables settings object
|
* @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
|
* @memberof DataTable#oApi
|
||||||
*/
|
*/
|
||||||
function _fnReDraw( oSettings )
|
function _fnReDraw( settings, holdPosition )
|
||||||
{
|
{
|
||||||
if ( oSettings.oFeatures.bSort )
|
var
|
||||||
{
|
features = settings.oFeatures,
|
||||||
/* Sorting will refilter and draw for us */
|
sort = features.bSort,
|
||||||
_fnSort( oSettings, oSettings.oPreviousSearch );
|
filter = features.bFilter;
|
||||||
|
|
||||||
|
if ( sort ) {
|
||||||
|
_fnSort( settings );
|
||||||
}
|
}
|
||||||
else if ( oSettings.oFeatures.bFilter )
|
|
||||||
{
|
if ( filter ) {
|
||||||
/* Filtering will redraw for us */
|
_fnFilterComplete( settings, settings.oPreviousSearch );
|
||||||
_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
// No filtering, so we want to just use the display master
|
||||||
_fnCalculateEnd( oSettings );
|
settings.aiDisplay = settings.aiDisplayMaster.slice();
|
||||||
_fnDraw( oSettings );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( holdPosition === false ) {
|
||||||
|
settings._iDisplayStart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fnCalculateEnd( settings );
|
||||||
|
_fnDraw( settings );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,11 @@ function _fnFeatureHtmlFilter ( oSettings )
|
|||||||
"bSmart": oPreviousSearch.bSmart ,
|
"bSmart": oPreviousSearch.bSmart ,
|
||||||
"bCaseInsensitive": oPreviousSearch.bCaseInsensitive
|
"bCaseInsensitive": oPreviousSearch.bCaseInsensitive
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// Need to redraw, without resorting
|
||||||
|
oSettings._iDisplayStart = 0;
|
||||||
|
_fnCalculateEnd( oSettings );
|
||||||
|
_fnDraw( oSettings );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
@ -113,13 +118,7 @@ function _fnFilterComplete ( oSettings, oInput, iForce )
|
|||||||
/* Tell the draw function we have been filtering */
|
/* Tell the draw function we have been filtering */
|
||||||
oSettings.bFiltered = true;
|
oSettings.bFiltered = true;
|
||||||
$(oSettings.oInstance).trigger('filter', oSettings);
|
$(oSettings.oInstance).trigger('filter', oSettings);
|
||||||
|
|
||||||
/* Redraw the table */
|
|
||||||
oSettings._iDisplayStart = 0;
|
|
||||||
_fnCalculateEnd( oSettings );
|
|
||||||
_fnDraw( oSettings );
|
|
||||||
|
|
||||||
/* Rebuild search array 'offline' */
|
|
||||||
_fnBuildSearchArray( oSettings, 0 );
|
_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
|
* 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)
|
* the table to look initialised for Ajax sourcing data (show 'loading' message possibly)
|
||||||
*/
|
*/
|
||||||
if ( oSettings.oFeatures.bSort )
|
_fnReDraw( oSettings );
|
||||||
{
|
|
||||||
_fnSort( oSettings );
|
|
||||||
}
|
|
||||||
else if ( oSettings.oFeatures.bFilter )
|
|
||||||
{
|
|
||||||
_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
|
|
||||||
_fnCalculateEnd( oSettings );
|
|
||||||
_fnDraw( oSettings );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if there is an ajax source load the data */
|
/* if there is an ajax source load the data */
|
||||||
if ( (oSettings.sAjaxSource || oSettings.ajax) && !oSettings.oFeatures.bServerSide )
|
if ( (oSettings.sAjaxSource || oSettings.ajax) && !oSettings.oFeatures.bServerSide )
|
||||||
@ -81,16 +68,7 @@ function _fnInitialise ( oSettings )
|
|||||||
*/
|
*/
|
||||||
oSettings.iInitDisplayStart = iAjaxStart;
|
oSettings.iInitDisplayStart = iAjaxStart;
|
||||||
|
|
||||||
if ( oSettings.oFeatures.bSort )
|
_fnReDraw( oSettings );
|
||||||
{
|
|
||||||
_fnSort( oSettings );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
|
|
||||||
_fnCalculateEnd( oSettings );
|
|
||||||
_fnDraw( oSettings );
|
|
||||||
}
|
|
||||||
|
|
||||||
_fnProcessingDisplay( oSettings, false );
|
_fnProcessingDisplay( oSettings, false );
|
||||||
_fnInitComplete( oSettings, json );
|
_fnInitComplete( oSettings, json );
|
||||||
|
@ -103,7 +103,7 @@ function _fnPageChange ( settings, action )
|
|||||||
_fnLog( settings, 0, "Unknown paging action: "+action );
|
_fnLog( settings, 0, "Unknown paging action: "+action );
|
||||||
}
|
}
|
||||||
|
|
||||||
var changed = settings._iDisplayStart === start;
|
var changed = settings._iDisplayStart !== start;
|
||||||
settings._iDisplayStart = start;
|
settings._iDisplayStart = start;
|
||||||
|
|
||||||
$(settings.oInstance).trigger('page', settings);
|
$(settings.oInstance).trigger('page', settings);
|
||||||
|
@ -230,20 +230,6 @@ function _fnSort ( oSettings, bApplyClasses )
|
|||||||
/* Tell the draw function that we have sorted the data */
|
/* Tell the draw function that we have sorted the data */
|
||||||
oSettings.bSorted = true;
|
oSettings.bSorted = true;
|
||||||
$(oSettings.oInstance).trigger('sort', oSettings);
|
$(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 */
|
/* Run the sort by calling a full redraw */
|
||||||
_fnSort( oSettings );
|
_fnReDraw( oSettings );
|
||||||
}; /* /fnInnerSorting */
|
}; /* /fnInnerSorting */
|
||||||
|
|
||||||
if ( !oSettings.oFeatures.bProcessing )
|
if ( !oSettings.oFeatures.bProcessing )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user