14

I am using the DataTables jQuery plugin. I am trying to enable sort interaction, but when sorting it sorts alphabetically and not numerically. As you can see in the enclosed picture, -4317.93 is shown after -631 and -456. How can I make DataTable sort a column numerically?

Example

1 Answer 1

21

Updated answer

With the latest version of DataTables you need to set the type property of the object you provide in the columnDefs array, like this:

$('#example').dataTable({
  "columnDefs": [
    { "type": "num" }
  ]
});

Note that there are many other methods of sorting which can be found in the documentation


Original answer

You need to add the sType parameter to your column definition.

For example:

$('#example').dataTable({
  "aoColumnDefs": [
    { "sType": "numeric" }
  ]
});

More information in the DataTable documentation: http://www.datatables.net/plug-ins/sorting

1
  • Thank you. This worked but when I applied this sort functionality of this column has been stopped working. Can you please let me know how to add sort functionality to this numeric column. Thanks in advance
    – Anuja P
    Feb 8, 2015 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.