Column filtering does not use column type for filtering
Column filtering does not use column type for filtering

Column filtering does not use column type (sType) for filtering. For example in a column defined as HTML it still searches HTML code. (While global filtering works as expected.)
(On 1.4.3.)
(On 1.4.3.)
This discussion has been closed.
Replies
Allan
[code]/* Updated function */
/*
* Function: _fnFilterColumn
* Purpose: Filter the table on a per-column basis
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* string:sInput - string to filter on
* int:iColumn - column to filter
* bool:bEscapeRegex - escape regex or not
*/
function _fnFilterColumn ( oSettings, sInput, iColumn, bEscapeRegex )
{
if ( sInput === "" )
{
return;
}
var iIndexCorrector = 0;
var sRegexMatch = bEscapeRegex ? _fnEscapeRegex( sInput ) : sInput;
var rpSearch = new RegExp( sRegexMatch, "i" );
for ( i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
{
var sData = _fnDataToSearch( oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[iColumn],
oSettings.aoColumns[iColumn].sType );
if ( ! rpSearch.test( sData ) )
{
oSettings.aiDisplay.splice( i, 1 );
iIndexCorrector++;
}
}
}
/* Updated function */
/*
* Function: _fnBuildSearchArray
* Purpose: Create an array which can be quickly search through
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* int:iMaster - use the master data array - optional
*/
function _fnBuildSearchArray ( oSettings, iMaster )
{
/* Clear out the old data */
oSettings.asDataSearch.splice( 0, oSettings.asDataSearch.length );
var aArray = (typeof iMaster != 'undefined' && iMaster == 1) ?
oSettings.aiDisplayMaster : oSettings.aiDisplay;
for ( i=0 ; i
It would be probably best to move this space adding from _fnDataToSearch function to _fnBuildSearchArray function. So:
oSettings.asDataSearch[i] += _fnDataToSearch( sData, oSettings.aoColumns[j].sType ) + ' ';
and:
function _fnDataToSearch ( sData, sType )
{
if ( sType == "html" )
{
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
}
else if ( typeof sData == "string" )
{
return sData.replace(/\n/g," ");
}
return sData;
}
Thanks,
Allan
Yes indeed - although to do anything useful with it you will need to add a filtering plug-in function, otherwise it will just filter it as a string. Have a look at the filtering plug-in page ( http://datatables.net/development/filtering ) for information on how to do this.
Regards,
Allan