Sorting columns is calculating numbers in my text?

Sorting columns is calculating numbers in my text?

ChrisGChrisG Posts: 29Questions: 0Answers: 0
edited August 2013 in DataTables 1.9
I have columns with the following data:

4/5
1

5/5
2

5/5
11

How can I get it to sort ascending like this:

5/5
11

5/5
2

4/5
1

So basically it just sorts the first line alphabetically and the second line numerically. Thanks in advance. :)

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Its sorting the column with "4/5" (for example) as a string since it contains non-numerical data (the `/` ). If you want it to sort numerically, you need to create a sorting plug-in that will calculate the decimal value from the fraction: http://datatables.net/development/sorting#type_based

    Allan
  • ChrisGChrisG Posts: 29Questions: 0Answers: 0
    I actually want to treat the fraction part as text only.

    So sort by the "4/5" text and then sort by the number below that. Is that possible?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sure - you just need to make a plug-in which will extract the fraction from the string, calculate the value as a decimal and use that sort the sorting in your sorting function.

    Allan
This discussion has been closed.