JQuery - datatable plugin - sorting problem

I am using the DataTables plugin from http://datatables.net .
The plugin itself is very useful, but I have a big problem with it.

It returns a list of addresses for some searches in the following format.

1 Main Street
12 Main Street
13 Main Street
14 Main Street
...
2 Main Street
3 Main Street
4 Main Street
5  Main Street
..

As you can see, sorting is not what I expected. Will return all numbers starting from 1 eg, 11, 111, 1111to 2.

Do any of you have experience with the plugin?

  • know solve this sorting problem?
  • or do you know a way to disable sorting on first initiation (display data as db forms arrive)?

Any suggestions that are very much appreciated.

+5
source share
2 answers

, natural-sort datatables. http://datatables.net/plug-ins/sorting ( " " ).

, , naturalSort, :

jQuery.fn.dataTableExt.oSort['natural-asc']  = function(a,b) {
    return naturalSort(a,b);
};

jQuery.fn.dataTableExt.oSort['natural-desc'] = function(a,b) {
    return naturalSort(a,b) * -1;
};

sSortDataType , , ( ):

$('#example').dataTable( {
    "aoColumns": [
        null,
        null,
        { "sType": "natural" }
]
});

http://jsfiddle.net/zhx32/14/

: , "aoColumns" , . Null , datatables .

+4

:

jQuery.fn.dataTableExt.oSort['num-html-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['num-html-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));
};

aoColumns

        "aoColumns": [
            null,
            null,
            null,
            { "sType": "num-html" },
            null
        ]
+3

All Articles