datables自定义排序

//百分率排序  
jQuery.fn.dataTableExt.oSort['number-fate-asc']  = function(s1,s2) {  
    s1 = s1.replace('%','');  
    s2 = s2.replace('%','');  
    return s1-s2;  
};  
  
jQuery.fn.dataTableExt.oSort['number-fate-desc'] = function(s1,s2) {  
    s1 = s1.replace('%','');  
    s2 = s2.replace('%','');  
    return s2-s1;  
};  
//中文排序  
jQuery.fn.dataTableExt.oSort['chinese-string-asc']  = function(s1,s2) {  
    return s1.localeCompare(s2);  
};  
jQuery.fn.dataTableExt.oSort['chinese-string-desc'] = function(s1,s2) {  
    return s2.localeCompare(s1);  
};   
2:指定排序的列:
[javascript] view plain copy print?
$('#flexme1').dataTable({  
    "aoColumns": [  
        null,  
        { "sType": "chinese-string" },//中文排序列  
        null,  
        { "sType": "number-fate" },//百分率排序  
        null,  
        null  
    ]  
});  
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "html-percent-pre": function(a) {
        var x = String(a).replace(/<[sS]*?>/g, ""); //去除html标记
        x = x.replace(/&amp;nbsp;/ig, ""); //去除空格
        x = x.replace(/%/, ""); //去除百分号
        return parseFloat(x);
    },

    "html-percent-asc": function(a, b) { //正序排序引用方法
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "html-percent-desc": function(a, b) { //倒序排序引用方法
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
});

 "sType": "html-percent",
原文地址:https://www.cnblogs.com/zjpzjp/p/7640929.html