1
jarlyyn 2015-08-13 19:39:10 +08:00
个人建议,传json或者转为js数组,用lodash/underscore排序。
|
2
loading 2015-08-13 19:48:59 +08:00 via Android
这个应该属于不读文档的伸手方式
|
4
CNCCTV OP |
5
jiaozhu 2015-08-13 22:12:17 +08:00
|
6
CNCCTV OP 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 刚才在别人指导下改写好了。 |