Datatables sort numbers is not working properly

datatable, datatables, javascript, jquery

Solution

Your problem is that for some reason the table data are treated as string and NOT as a number. Check the formatting of your values.

If fore example you have something like this:

<table .....>
  <tbody>
    <tr>
      <td><span>1</span></td>
    </td>
    ....
  </tbody>
</table>

Then Datatables will treat the value of that column as a string and not as a Number. This is common if you are outputting the text with a framework such as asp .NET.

See this for a similar problem

Problem

I use datatables on my page, it seems to work fine, except that when you do sorting on the number field, it sorts in a weird way, take a look at the illustration This one also I have tried to place ``` "aoColumns": [ null, null, null, null, null, null, { "sType": 'numeric', "oCustomInfo":{ "decimalPlaces":1, "decimalSeparator":"."} }, null ] ``` But this seems to further disturbs its behaviour as it becomes unsortable. Do you have a clue ? Thanks

Original source