• DataTable自定义排序


    使用JQ DataTable 的时候,希望某列数据可以进行自定义排序,操作如下:(以中文排序和百分比排序为例)

    1:定义排序类型:

     
    1. //百分率排序  
    2. jQuery.fn.dataTableExt.oSort['number-fate-asc']  = function(s1,s2) {  
    3.     s1 = s1.replace('%','');  
    4.     s2 = s2.replace('%','');  
    5.     return s1-s2;  
    6. };  
    7.   
    8. jQuery.fn.dataTableExt.oSort['number-fate-desc'] = function(s1,s2) {  
    9.     s1 = s1.replace('%','');  
    10.     s2 = s2.replace('%','');  
    11.     return s2-s1;  
    12. };  
    13. //中文排序  
    14. jQuery.fn.dataTableExt.oSort['chinese-string-asc']  = function(s1,s2) {  
    15.     return s1.localeCompare(s2);  
    16. };  
    17. jQuery.fn.dataTableExt.oSort['chinese-string-desc'] = function(s1,s2) {  
    18.     return s2.localeCompare(s1);  
    19. };   



    2:指定排序的列:

     
      1. $('#flexme1').dataTable({  
      2.     "aoColumns": [  
      3.         null,  
      4.         { data: 'area', "sType": "chinese-string" },//中文排序列  
      5.         null,  
      6.         { data: 'percent', "sType": "number-fate" },//百分率排序  
      7.         null,  
      8.         null  
      9.     ]  
      10. });
  • 相关阅读:
    面向对象基本原则
    策略模式
    简单工厂模式
    高内聚、低耦合
    UML在代码中的展现
    使用commons-csv简单读写CSV文件
    java反射机制
    SrpingDruid数据源加密数据库密码
    markdown学习经验
    Vue.js学习笔记
  • 原文地址:https://www.cnblogs.com/shijiaoyun/p/6141119.html
Copyright © 2020-2023  润新知