Old code doesn't work at all with recent DataTables

Besides, old script would not match `10 GB` and other types of format. My example is not perfectly complete but at least it works.
pull/170/head
Ilia Rostovtsev 10 years ago
parent e1522933c1
commit 369e7a8e2b

@ -1,36 +1,23 @@
/**
* Detect "file size" type columns automatically. Commonly used for computer
* file sizes, this can allow sorting to take the order of magnitude indicated
* by the label (GB etc) into account.
* by the label (GB, MB, Unlimited etc) into account.
*
* @name File size
* @summary Detect abbreviated file size data (8MB, 4KB etc)
* @author _anjibman_
* @summary Detect abbreviated file size data (8 MB, 4KB, 10TB, Unlimited, No Limit etc)
* @author Ilia Rostovtsev (https://rostovtsev.ru)
*/
jQuery.fn.dataTableExt.aTypes.unshift(
$.fn.dataTable.ext.type.detect.unshift(
function ( sData )
{
var sValidChars = "0123456789";
var Char;
/* Check the numeric part */
for ( var i=0 ; i<(sData.length - 3) ; i++ )
/* Check for size unit KB, MB, GB, TB */
if ( /((\d+(\s+)|\d+\.\d+(\s+)))(TB|GB|MB|KB|Byte|Bytes|ГБ|МБ|КБ|Байт)|(Unlimited|Ubegrenset|Nielimitowane|Ilimitado|无限制|No Limit)/i.test(sData) )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
return 'file-size';
} else
{
return null;
}
}
/* Check for size unit KB, MB or GB */
if ( sData.substring(sData.length - 2, sData.length) == "KB"
|| sData.substring(sData.length - 2, sData.length) == "MB"
|| sData.substring(sData.length - 2, sData.length) == "GB" )
{
return 'file-size';
}
return null;
}
);

Loading…
Cancel
Save