Sorting integers

Sorting integers

davebridgesdavebridges Posts: 3Questions: 0Answers: 0
edited August 2010 in General
With 1.7, i have a table with several integer values. If i sort by this column they get sorted like this:

9
8
6
5
3
22
21
20
2
19
18
17

etc...

It seems to be sorting by the first digit of the integer. Is there some setting i can use to fix this?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    If ate is happening then DataTables is most likely treating your column as a 'string' typed column. This suggests that you have non-numeric data somewhere in the column, since the automatic type detection isn't picking this up. Can you post a link to an example showing the issue?

    Allan
  • davebridgesdavebridges Posts: 3Questions: 0Answers: 0
    i cant really post an example... but there are only digits shown in the column. There is one value per cell, and no empty cells. Is there a way to force it to treat the column as an integer?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Yes you can set the 'sType' to "numeric": http://datatables.net/usage/columns#sType

    However - it should work automatically - as showing in the fourth column here: http://datatables.net/

    Allan
  • davebridgesdavebridges Posts: 3Questions: 0Answers: 0
    I forgot to mention that my integer was also a hyperlink. I removed the tags around it and it sorted fine. It must have detected it as html... then converted it to string rather than integer. Works great now, thanks for all the help
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    This is the plug-in that is needed to sort HTML wrapped numbers: http://datatables.net/plug-ins/sorting#numbers_html

    Allan
  • r_dogsr_dogs Posts: 1Questions: 0Answers: 0
    I had this problem too. Thanks a lot Allan for your responses.

    I had trouble understanding the documentation, and didn't know that the sType needed to be "num-html".
This discussion has been closed.