zoukankan      html  css  js  c++  java
  • 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. });
  • 相关阅读:
    HTML5新媒体元素
    概述
    (一)最小可行化应用
    JSON
    ajax的工作原理
    R语言学习笔记(四)
    R语言学习笔记(一)
    转:禅道的数据库结构
    转:bug的分类和等级
    转:如何定义 Bug 的优先级
  • 原文地址:https://www.cnblogs.com/shijiaoyun/p/6141119.html
Copyright © 2011-2022 走看看