0

I have a datatable on my website and try to sort numbers with 1,999,999,999 but it doesn't work. I tried to fix the problem with a lot of tips on Google but it does not helped me.

Thats the javascript code for my table

$('.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
                ]
    });

Here is the Datatable where i try to sort the numbers.

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

Tevo D
  • 3,351
  • 21
  • 28
MatzejiiN
  • 1
  • 1

1 Answers1

1

You can try it, we overwrite DataTable sort function, and replace ",".

    <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>
Tin
  • 11
  • 1