You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
/**
|
|
* This type-detection plug-in will look at an HTML string from a data cell,
|
|
* strip the HTML tags and then check to see if the remaining data is numeric.
|
|
* If it is, then the data can be sorted numerically with the Numbers with HTML
|
|
* sorting plug-in.
|
|
* @name Numbers with HTML
|
|
* @anchor numbers_html
|
|
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
|
|
*/
|
|
|
|
jQuery.fn.dataTableExt.aTypes.unshift( function ( sData )
|
|
{
|
|
sData = typeof sData.replace == 'function' ?
|
|
sData.replace( /<.*?>/g, "" ) : sData;
|
|
sData = $.trim(sData);
|
|
|
|
var sValidFirstChars = "0123456789-";
|
|
var sValidChars = "0123456789.";
|
|
var Char;
|
|
var bDecimal = false;
|
|
|
|
/* Check for a valid first char (no period and allow negatives) */
|
|
Char = sData.charAt(0);
|
|
if (sValidFirstChars.indexOf(Char) == -1)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/* Check all the other characters are valid */
|
|
for ( var i=1 ; i<sData.length ; i++ )
|
|
{
|
|
Char = sData.charAt(i);
|
|
if (sValidChars.indexOf(Char) == -1)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/* Only allowed one decimal place... */
|
|
if ( Char == "." )
|
|
{
|
|
if ( bDecimal )
|
|
{
|
|
return null;
|
|
}
|
|
bDecimal = true;
|
|
}
|
|
}
|
|
|
|
return 'num-html';
|
|
} );
|