DataTable column sorting incorrectly

Isaac
Isaac used Ask the Experts™
on
I have a dataTable and I'm populating the table with data from a list.  One of my columns in the datatable is a textbox for users to manipulate.  In SharePoint, the column is a number column.  I do notice that when I sort it in the dataTable, it's not sorted correctly, even if I force it with a parseInt.  If not in a textbox, it sorts correctly. See pic below.

DT Table
Any ideas how to fix?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
It's sorting as a string instead of sorting as a number.  To correct that, set the column data type.

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

Open in new window


"targets" is the column number.  The first column is 0.

Here's the documentation:  https://datatables.net/reference/option/columns.type
IsaacSharePoint Client Side Developer

Author

Commented:
Thank you so much!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial