DataTables对货币进行排序

use*_*034 4 sorting format currency datatables

请帮助实例,如何以"34 566.00 ek"格式对货币进行分类.在DataTables脚本中.

这是JSFiddle的例子:http://jsfiddle.net/HEDvf/643/

$('#example').dataTable({
   "aoColumns": [
    null,
   ],        
  "aaSorting": [[ 0, "desc" ]],
  "bStateSave": false,
  "iDisplayLength": 50,
});
Run Code Online (Sandbox Code Playgroud)

Gig*_*igo 11

查看非常广泛的数据表文档.在那里,您将找到几乎所有与数据表有关的问题的简单解决方案.例如,有一些小插件函数可以为货币列添加排序支持.

基于你得到的一个例子:

// add sorting methods for currency columns
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "currency-pre": function (a) {
        a = (a === "-") ? 0 : a.replace(/[^\d\-\.]/g, "");
        return parseFloat(a);
    },
    "currency-asc": function (a, b) {
        return a - b;
    },
    "currency-desc": function (a, b) {
        return b - a;
    }
});

// initialize datatable and explicitly set the column type to "currency"
$('#example').dataTable({
    "aoColumns": [{"sType": "currency"}],
    "aaSorting": [[0, "desc"]],
    "bStateSave": false,
    "iDisplayLength": 50,
});
Run Code Online (Sandbox Code Playgroud)

文档链接:

排序:http://datatables.net/plug-ins/sorting#currency

数据表还能够自动检测列类型,但是所有不同的格式都会有点复杂.类型检测:http://datatables.net/plug-ins/type-detection#currency