DataTables – fnFilter match blank space regexp


Wow, I had to dig into the source of DataTables 1.9.3 to figure out why a regular expression with no “smart filter” was failing.

Turns out each column is returning massively padded data due to the HTML blocks containing spaces.

Trim it to match regexps that rely on position like ^$ (blank) or .+ (1+). Those extra leading/trailing whitespace chars are the problem.

Go to the DataTables source… look at this function and trim whitespace from sData:

Note that there may be an API for overriding internal functions… but I can’t be bothered to look right now. This has been a long debug.

		function _fnFilterColumn ( oSettings, sInput, iColumn, bRegex, bSmart, bCaseInsensitive )
			if ( sInput === "" )
			var iIndexCorrector = 0;
			var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart, bCaseInsensitive );
			for ( var i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
				var sData = _fnDataToSearch( _fnGetCellData( oSettings, oSettings.aiDisplay[i], iColumn, 'filter' ),
					oSettings.aoColumns[iColumn].sType );
				if ( ! rpSearch.test( sData.trim() ) ) ////////// add .trim() here

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s