dataTables does not sort numbers correctly with string

0

I have a table where I use the dataTables plugin and in some columns (in several of them) have values that contain numbers + string. An example column:

Itshouldbesortingfromhighesttolowestwhenyouclick,butbyclickingonthecolumnitbringsmeliketheimageaboveandtherightonewouldbe:

246.0Mio169.0Mio131.0Mio109.0Mio...40.0Mio

Ihavethecode:

$('#datatable_noSearchNoPagination,#datatable_noSearchNoPagination2').dataTable({"searching": false,
   'paging': false
});
    
asked by anonymous 28.06.2017 / 22:18

2 answers

0

The ordering is correct because the values are of type STRING and therefore a "40" comes after a "100" in the same way that "Z" comes after "ABC".

    
28.06.2017 / 22:27
0

The datatable is detailed, so I recommend spending some time reading the API because it makes it easier to use. You can use:

$ ('# example'). DataTable ({ "order": [[3, "desc"]] });

Or

table .order ([1, 'asc']) .draw ();

Or if you order in your query then disable the order as below

$ ('# example'). dataTable ({   "ordering": false });

REF: link

    
29.06.2017 / 13:26