jQuery.extend( jQuery.fn.dataTableExt.oSort, {
/*
* 文件 KB MB GB 排序
* 点击排序后优先执行*-pre,随后执行*-asc 或 *-desc
*
* "aoColumnDefs": [
* { "sType": "cfl", "aTargets": [0]}, //指定列号使用自定义排序
* { "sType": "cfl", "aTargets": [1]},
* { "sType": "cfl", "aTargets": [2]},
* { "sType": "cfl", "aTargets": [3]},
* { "sType": "cfl", "aTargets": [4]},
* ],
*
*/
"cfl-pre" : function (str) {
x = String(str).replace(/\d+(\.\d+)*/, ""); //替换所有数字符并转为number类型
console.log(x);
z = Number(String(str).replace(/(KB|MB|GB)/, ""));
console.log(z);
var multiplier = 1;
if ( x === 'KB' ) {
multiplier = 1024;
}
else if ( x === 'MB' ) {
multiplier = 1048576;
}
else if ( x === 'GB' ) {
multiplier = 1073741824;
}
z = z * multiplier;
return z;
},
"cfl-asc" : function (s1, s2) {
return (s1 < s2) ? -1 : ((s1 > s2) ? 1 : 0);
},
"cfl-desc" : function (s1, s2) {
return ((s1 < s2) ? 1 : ((s1 > s2) ? -1 : 0));
}
} );
@
jiaozhu 刚才在别人指导下改写好了。