Wrong sorting in a row

Wrong sorting in a row

DennisABDennisAB Posts: 2Questions: 1Answers: 0

Hi guys,
I have a table with datatable with an id row (0 index) that shows a list of questions and answers provided by a web thats works fine until the id >100... in that case the sorting is lost. At first point of view this is sorting wrong when the id >100 and the filter query select a previous period. Heres the code

$content.find("table.datatable").dataTable({
//"sPaginationType": "full_numbers",
"oLanguage": { "sUrl": "/js/datatable_spanish.txt" },
//"aaSorting": [[ 0, "desc" ]],
"iDisplayLength": 20,
"aoColumns": [
{ "sType": "numeric" },
{ "sType": "date" },
null,
null,
null,
null,
null,
null
]
});

looks like this

1 | 09/09
2 | 10/09
101 | 02/10
3 | 11/09...

Thanks in advance

Answers

  • DennisABDennisAB Posts: 2Questions: 1Answers: 0
    edited July 2014

    Solved, only using a plugin:

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

    And then apply to content:

    "sPaginationType": "full_numbers",
                    "aaSorting": [[ 0, "asc" ]],
                    "iDisplayLength": 10,
                    "oLanguage": { "sUrl": "/js/datatable_spanish.txt" },
                    "aoColumns": [
                        { "sType": "title-numeric", "bSortable": true },
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null
                    ],
    
This discussion has been closed.