zoukankan      html  css  js  c++  java
  • 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",
  • 相关阅读:
    OO第二单元总结-上上下下的快乐
    OO第一单元总结
    OO第四单元博客作业
    OO第三单元博客作业
    OO第二单元博客作业
    OO第一次博客作业
    Python Selenium实现浏览器自动化操作
    Python命名规范
    OO_UNIT4 & OO_2020 SUMMARY
    OO_UINT3_2020
  • 原文地址:https://www.cnblogs.com/zjpzjp/p/7640929.html
Copyright © 2011-2022 走看看