Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables sort numbers is not working properly

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

enter image description here

This one also

enter image description here

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

like image 361
Digital fortress Avatar asked Nov 28 '13 19:11

Digital fortress


1 Answers

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

like image 77
MaVRoSCy Avatar answered Nov 02 '22 05:11

MaVRoSCy