Update to current type detection - Nuno Gomes points out that European convention is not always to have the € first - you can have it at the end etc. As such, rewrite this plug-in to be a lot more lenient as to how it detects currency. Also use a regex rather than looping over the characters externally, and cope with non-string data.

pull/2/head
Allan Jardine 13 years ago
parent 29be7c6fb7
commit 7ae25e7d8d

@ -8,27 +8,27 @@
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>, Nuno Gomes * @author <a href="http://sprymedia.co.uk">Allan Jardine</a>, Nuno Gomes
*/ */
jQuery.fn.dataTableExt.aTypes.unshift( (function(){
function ( sData )
{ // Change this list to the valid characters you want
var sValidChars = "0123456789.-,"; var validChars = "$£€c" + "0123456789" + ".-,'";
var sValidSymbols = "$£€";
var c; // Init the regex just once for speed - it is "closure locked"
var symbolMatch = false; var
str = jQuery.fn.dataTableExt.oApi._fnEscapeRegex( validChars ),
re = new RegExp('[^'+str+']');
if ( sValidSymbols.indexOf( sData.charAt(0) ) === -1 ) {
return null;
}
for ( i=1 ; i<sData.length ; i++ ) { jQuery.fn.dataTableExt.aTypes.unshift(
// check for valid chars function ( data )
c = sData.charAt(i); {
if (sValidChars.indexOf(c) === -1) { if ( typeof data !== 'string' || re.test(data) ) {
return null; return null;
} }
}
// currency detected
return 'currency'; return 'currency';
} }
); );
}());

Loading…
Cancel
Save