diff --git a/media/src/api/api.methods.js b/media/src/api/api.methods.js index f78a07f5..6f9481c3 100644 --- a/media/src/api/api.methods.js +++ b/media/src/api/api.methods.js @@ -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 ); }; diff --git a/media/src/core/core.draw.js b/media/src/core/core.draw.js index 71c80833..46234743 100644 --- a/media/src/core/core.draw.js +++ b/media/src/core/core.draw.js @@ -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 ); } diff --git a/media/src/core/core.filter.js b/media/src/core/core.filter.js index 358fce44..ccfad17d 100644 --- a/media/src/core/core.filter.js +++ b/media/src/core/core.filter.js @@ -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 ); } } ); @@ -113,13 +118,7 @@ function _fnFilterComplete ( oSettings, oInput, iForce ) /* Tell the draw function we have been filtering */ 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 ); } diff --git a/media/src/core/core.init.js b/media/src/core/core.init.js index 8038e468..b9805349 100644 --- a/media/src/core/core.init.js +++ b/media/src/core/core.init.js @@ -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 ); diff --git a/media/src/core/core.page.js b/media/src/core/core.page.js index 6d90507e..e1f0899a 100644 --- a/media/src/core/core.page.js +++ b/media/src/core/core.page.js @@ -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); diff --git a/media/src/core/core.sort.js b/media/src/core/core.sort.js index abb1e3bb..61825926 100644 --- a/media/src/core/core.sort.js +++ b/media/src/core/core.sort.js @@ -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 )