Search code examples
jquerysortingtablesorter

Weird behaviour sorting in Tablesorter pluggin


I'm using this great pluggin from JQuery called Tablesorter. The documentation is from https://mottie.github.io/tablesorter/docs/index.html

If I sort via SQL, I get the expected behavior like this next image:

enter image description here

But when I sort via the tablesorter I get a wrong behavior as it is shown in the next image:

enter image description here

Is There an option to allow tablesorter sorting as SQL does?

I think that the problem only appears when the content is mixed with letters and numbers, but not sure at all.

Thank you very much for the help in advance!


Solution

  • The problem is the first cell contains all numeric values 010844005. So the parser detection assumes that column is to be sorted numerically.

    To fix this issue, set the column to sort by text. Do this by either:

    • Setting a sorter-text class in the header cell

      <th class="sorter-text">Referencia</th>
      
    • Setting the headers option for that column

      $('table').tablesorter({
        headers: {
          0: { sorter: 'text' }
        }
      });