2014-02-26 27 views

回答

0

您应该能够使用Formatted Numbers自定义排序插件,它可以在Datatables Plugin Section

本质上可以找到,你排序的列时调用下面的代码。

jQuery.extend(jQuery.fn.dataTableExt.oSort, { 
    "formatted-num-pre": function (a) { 
     a = (a === "-" || a === "") ? 0 : a.replace(/[^\d\-\.]/g, ""); 
     return parseFloat(a); 
    }, 

    "formatted-num-asc": function (a, b) { 
     return a - b; 
    }, 

    "formatted-num-desc": function (a, b) { 
     return b - a; 
    } 
}); 

你告诉数据表通过设置您的初始化代码的aoColumns对象为你的餐桌

$(document).ready(function() { 
     $('#example').dataTable({ 
      "aoColumns": [ 
       null, // each of these = a column in your table 
       null, 
       null, 
       // this column, 4th, will be sorted usig the plugin 
       { "sType": "formatted-num-pre" }, 
       null 
      ] 
     }); 
    }); 

还有一个Natural sorting插件,同一个页面,可能有助于在使用这种。

最终,您可以通过以下示例创建自己的插件。

相关问题