Ids get ordered alphabetically instead of numerically
-
11-09-2019 - |
Question
I am pulling out data from MySQL ordered by id, which is 1,2,3 and there is no problem.
However when I use it with http://www.datatables.net/, the order becomes 1, 10, 11 ,12,..
I am not able find any parameter to sort this problem.
I am wondering if anyone knows how to fix this.
$(document).ready( function() {
$("#tablesorter").dataTable( {
"iDisplayLength": 40,
"oLanguage": {
"sLengthMenu": 'Display <select>'+
'<option value="20">20</option>'+
'<option value="40">40</option>'+
'<option value="60">60</option>'+
'<option value="80">80</option>'+
'<option value="100">100</option>'+
'<option value="-1">All</option>'+
'</select> records'
}
} );
} )
Solution
It sounds like you need to set the column type of that column to numeric, in order for the sort to work correctly. This is detailed at the data tables website
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow