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

Loading…
Cancel
Save