1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-03-15 16:29:16 +01:00

Fix: Modify the filtering such that client-side filtering is not done when server-side processing is enabled - its just a waste of time since hte server will do it all - 7825

This commit is contained in:
Allan Jardine 2011-12-21 09:07:44 +00:00
parent 3f9b7430f1
commit 74f3426284
2 changed files with 66 additions and 36 deletions

View File

@ -2029,21 +2029,39 @@
*/ */
function _fnFilterComplete ( oSettings, oInput, iForce ) function _fnFilterComplete ( oSettings, oInput, iForce )
{ {
/* Filter on everything */ var oPrevSearch = oSettings.oPreviousSearch;
_fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive ); var aoPrevSearch = oSettings.aoPreSearchCols;
var fnSaveFilter = function ( oFilter ) {
/* Now do the individual column filter */ /* Save the filtering values */
for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ ) oPrevSearch.sSearch = oFilter.sSearch;
oPrevSearch.bRegex = oFilter.bRegex;
oPrevSearch.bSmart = oFilter.bSmart;
oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
};
/* In server-side processing all filtering is done by the server, so no point hanging around here */
if ( !oSettings.oFeatures.bServerSide )
{ {
_fnFilterColumn( oSettings, oSettings.aoPreSearchCols[i].sSearch, i, /* Global filter */
oSettings.aoPreSearchCols[i].bRegex, oSettings.aoPreSearchCols[i].bSmart, _fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive );
oSettings.aoPreSearchCols[i].bCaseInsensitive ); fnSaveFilter( oInput );
/* Now do the individual column filter */
for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ )
{
_fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex,
aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
}
/* Custom filtering */
if ( DataTable.ext.afnFiltering.length !== 0 )
{
_fnFilterCustom( oSettings );
}
} }
else
/* Custom filtering */
if ( DataTable.ext.afnFiltering.length !== 0 )
{ {
_fnFilterCustom( oSettings ); fnSaveFilter( oInput );
} }
/* Tell the draw function we have been filtering */ /* Tell the draw function we have been filtering */
@ -2133,6 +2151,7 @@
{ {
var i; var i;
var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive ); var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
var oPrevSearch = oSettings.oPreviousSearch;
/* Check if we are forcing or not - optional parameter */ /* Check if we are forcing or not - optional parameter */
if ( !iForce ) if ( !iForce )
@ -2161,8 +2180,8 @@
* then the old one (i.e. delete). Search from the master array * then the old one (i.e. delete). Search from the master array
*/ */
if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length || if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
oSettings.oPreviousSearch.sSearch.length > sInput.length || iForce == 1 || oPrevSearch.sSearch.length > sInput.length || iForce == 1 ||
sInput.indexOf(oSettings.oPreviousSearch.sSearch) !== 0 ) sInput.indexOf(oPrevSearch.sSearch) !== 0 )
{ {
/* Nuke the old display array - we are going to rebuild it */ /* Nuke the old display array - we are going to rebuild it */
oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length); oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
@ -2200,10 +2219,6 @@
} }
} }
} }
oSettings.oPreviousSearch.sSearch = sInput;
oSettings.oPreviousSearch.bRegex = bRegex;
oSettings.oPreviousSearch.bSmart = bSmart;
oSettings.oPreviousSearch.bCaseInsensitive = bCaseInsensitive;
} }

View File

@ -70,21 +70,39 @@ function _fnFeatureHtmlFilter ( oSettings )
*/ */
function _fnFilterComplete ( oSettings, oInput, iForce ) function _fnFilterComplete ( oSettings, oInput, iForce )
{ {
/* Filter on everything */ var oPrevSearch = oSettings.oPreviousSearch;
_fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive ); var aoPrevSearch = oSettings.aoPreSearchCols;
var fnSaveFilter = function ( oFilter ) {
/* Now do the individual column filter */ /* Save the filtering values */
for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ ) oPrevSearch.sSearch = oFilter.sSearch;
oPrevSearch.bRegex = oFilter.bRegex;
oPrevSearch.bSmart = oFilter.bSmart;
oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
};
/* In server-side processing all filtering is done by the server, so no point hanging around here */
if ( !oSettings.oFeatures.bServerSide )
{ {
_fnFilterColumn( oSettings, oSettings.aoPreSearchCols[i].sSearch, i, /* Global filter */
oSettings.aoPreSearchCols[i].bRegex, oSettings.aoPreSearchCols[i].bSmart, _fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart, oInput.bCaseInsensitive );
oSettings.aoPreSearchCols[i].bCaseInsensitive ); fnSaveFilter( oInput );
/* Now do the individual column filter */
for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ )
{
_fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex,
aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
}
/* Custom filtering */
if ( DataTable.ext.afnFiltering.length !== 0 )
{
_fnFilterCustom( oSettings );
}
} }
else
/* Custom filtering */
if ( DataTable.ext.afnFiltering.length !== 0 )
{ {
_fnFilterCustom( oSettings ); fnSaveFilter( oInput );
} }
/* Tell the draw function we have been filtering */ /* Tell the draw function we have been filtering */
@ -174,6 +192,7 @@ function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart, bCaseInsensitive
{ {
var i; var i;
var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive ); var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
var oPrevSearch = oSettings.oPreviousSearch;
/* Check if we are forcing or not - optional parameter */ /* Check if we are forcing or not - optional parameter */
if ( !iForce ) if ( !iForce )
@ -202,8 +221,8 @@ function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart, bCaseInsensitive
* then the old one (i.e. delete). Search from the master array * then the old one (i.e. delete). Search from the master array
*/ */
if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length || if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
oSettings.oPreviousSearch.sSearch.length > sInput.length || iForce == 1 || oPrevSearch.sSearch.length > sInput.length || iForce == 1 ||
sInput.indexOf(oSettings.oPreviousSearch.sSearch) !== 0 ) sInput.indexOf(oPrevSearch.sSearch) !== 0 )
{ {
/* Nuke the old display array - we are going to rebuild it */ /* Nuke the old display array - we are going to rebuild it */
oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length); oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
@ -241,10 +260,6 @@ function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart, bCaseInsensitive
} }
} }
} }
oSettings.oPreviousSearch.sSearch = sInput;
oSettings.oPreviousSearch.bRegex = bRegex;
oSettings.oPreviousSearch.bSmart = bSmart;
oSettings.oPreviousSearch.bCaseInsensitive = bCaseInsensitive;
} }