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