Muhanad Muneer Muhanad Muneer - 2 months ago 17
jQuery Question

Wrong sorting decimal values tablesorter script

I have problem while sorting decimal values table sorter grid.
When I try to sort distance values in the table the distance sort as follows :

distance
0.35
0.76
1.36
1.75
10.36
100.66
2.33

$(document).ready(function() {
// extend the default setting to always include the zebra widget.
$.tablesorter.defaults.widgets = ['zebra'];
// extend the default setting to always sort on the first column
$.tablesorter.defaults.sortList = [[0,0]];
$.tablesorter.defaults.debug=true;
$("table#list").tablesorter();
});
$(document).ready(function() {

$("table#list").tablesorterPager({container: $("#pager")});
});


Can any one tell me what's the solution to prevent wrong sorting ?

Answer

Try setting the sorter to digit in the header option:

$(function() {
  $("table#list").tablesorter({
    widgets  : ['zebra'],
    sortList : [[0,0]]
    headers  : {
      0 : { sorter : 'digit' }
    }
  }).tablesorterPager({
    container: $("#pager")
  }); 
});
Comments