i have a table with several integer values. If i sort by this column they get sorted like this: 9 8

i have a table with several integer values. If i sort by this column they get sorted like this: 9 8

charles19192charles19192 Posts: 3Questions: 1Answers: 0

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?

Answers

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955

    Sounds like your data is being sorted as a string not a number. Datatables does some type checking of the data in each column and for some reason set the column type to string. It would do this if you have non-numeric data in the column. Do you have non-numeric data in that column?

    Kevin

  • charles19192charles19192 Posts: 3Questions: 1Answers: 0
    edited June 2022

    yes Sir, there is non-numeric data in that column and It's a bracket. ()

    I have taken the brackets off but the issue still persists.

    Any ideas that might help?

    thanks

    Charles

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Without a link to a test case showing the issue we can't say specifically what data value is causing the problem, but as Kevin noted, it will still be that there is non-numeric data in the column somewhere.

    If you are using brackets for negative numbers, then this plug-in will sort them correctly for you. But we'd still need to identify any other data detected as non-numeric.

    Allan

  • charles19192charles19192 Posts: 3Questions: 1Answers: 0
    edited June 2022

    Thanks @ Allan,

    please I'm new to this

    can't I post a link
    but can I post snippets of the code?

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955
    edited June 2022

    Try the plugin Allan linked to if your parenthesis are used for negative numbers. If that doesn't help then we will need to see something that shows all the different examples of non-numeric data you have. We need to understand what your non-numeric data is and how you want to handle it for sorting to offer other suggestions. The best way to do this is to create a test case with sample data that we can look at.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Another option is to use Orthogonal data to remove the non-numeric characters using columns.render for the sort operation.

    Kevin

Sign In or Register to comment.