Jquery数据表:带逗号的排序号不起作用

waw*_*los 2 javascript sorting jquery datatables

我正在尝试使用逗号(,)对带有数字的列进行排序.

我使用num-fmt选项得到错误的结果:

在此输入图像描述

这是我的代码:

$('#test').DataTable({
    columnDefs: [
         { targets: 4, type: 'num-fmt' }
    ]
});
Run Code Online (Sandbox Code Playgroud)

Gyr*_*com 6

使用数字逗号插件正确排序数字,使用逗号作为小数位.

//cdn.datatables.net/plug-ins/1.10.11/sorting/numeric-comma.js如下所示包括或使用内联:

$.extend( $.fn.dataTableExt.oSort, {
    "numeric-comma-pre": function ( a ) {
        var x = (a == "-") ? 0 : a.replace( /,/, "." );
        return parseFloat( x );
    },

    "numeric-comma-asc": function ( a, b ) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "numeric-comma-desc": function ( a, b ) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
} );

$('#test').DataTable({
    columnDefs: [
         { targets: 4, type: 'numeric-comma' }
    ]
});
Run Code Online (Sandbox Code Playgroud)