0

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

那是我的表的 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

4

1 回答 1

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>
于 2014-02-26T03:55:10.877 回答