数据表排序编号不起作用

时间:2013-07-24 13:59:52

标签: sorting datatable numbers

我的网站上有一个数据表,并尝试用1,999,999,999对数字进行排序,但它不起作用。我尝试用Google上的很多提示解决问题,但这对我没有帮助。

这是我桌子的javascript代码

$('.d3uitems').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "sDom": '<""l>t<"F"p>',
        'aaSorting': [[ 0, 'desc' ]]
    }).columnFilter({
            aoColumns: [ null,
                     { type: "text"},
                         null,
                     null,
                     { type: "text"},
                     null
                ]
    });

这是我试图对数字进行排序的数据表。

http://www.lootfinder.net/index.php?page=d3uitems

1 个答案:

答案 0 :(得分:1)

您可以尝试,我们覆盖DataTable排序功能,并替换“,”。

    <script type="text/javascript" charset="utf-8">

        jQuery.fn.dataTableExt.oSort['numeric-comma-asc']  = function(a,b) {
            var x = (a == "-") ? 0 : a.replace( /,/g,"" );
            var y = (b == "-") ? 0 : b.replace( /,/g,"" );
            alert( "x=" + x );
            x = parseFloat( x );
            y = parseFloat( y );
            return ((x < y) ? -1 : ((x > y) ?  1 : 0));
        };

        jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
            var x = (a == "-") ? 0 : a.replace( ",","" );
            var y = (b == "-") ? 0 : b.replace( ",","" );
            x = parseFloat( x );
            y = parseFloat( y );
            return ((x < y) ?  1 : ((x > y) ? -1 : 0));
        };


        $(document).ready(function() {
            $('#example').dataTable( {
                "sPaginationType": "full_numbers",
                "bPaginate": false,
                "aoColumns": [
                                null,
                                null,
                                null,
                                { "sType": "numeric-comma" },
                                null
                ]
            } );

        } );
    </script>