broken sort, only sorts first 2 digits

broken sort, only sorts first 2 digits

nomexnomex Posts: 2Questions: 0Answers: 0
edited December 2009 in General
Hey,

i can't find any solution. sorting my table results for example in this order:

0.1
10.8
10.20
103.20
108.50
11.30
11.2

i convertet the csv input with php to float.

it seems he only sort the frist 2 digits. Anyone knows how to fix this problem?

thx mike

Replies

  • nomexnomex Posts: 2Questions: 0Answers: 0
    nobody has an idea what i'm doing wrong?

    same happens when i cut out the decimal places...

    only the first digits are sorted...
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi nomex,

    My guess is that you have white space in the table cell. In order to sort numerically, DataTables requires that you have only numeric ( [0-9]\-\. ) in the cell, otherwise it will be sorted as a string - which is what is happening here.

    So remove any white space and any other non-numeric data and it will work fine.

    If you don't want to remove the white space etc, then you can use the sorting plug-in "formatted numbers" ( http://datatables.net/plug-ins/sorting#formatted_numbers ) which will strip these non-numeric characters for you. The disadvantage of this is that sorting is slightly slower due to the additional processing.

    Regards,
    Allan
This discussion has been closed.