Sorting on numbers in a text

Sorting on numbers in a text

arnorbldarnorbld Posts: 123Questions: 23Answers: 1

Hi guys,

I have a table using DT that shows a list of folders and files fetched from Google Drive via API. The folders are all named like this:
A00001-Smith
A00002-John
A100001-Brandon

The problem is that the A100001-Brandon shows up at the top because it's sorted alphabetically. Somehow Google Drive figures this out and sorts it in numerical order after the A.

I need it to show in the correct numerical order:
A100001-Brandon
A00001-Smith
A00002-John

My idea was to use a hidden column where I just have the numbers and used that for sorting the folders and it would be used when sorting on the folder/filename.

Any idea how I can accomplish this?

Best regards,

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Maybe the Natural during plugin will help. There might be other sorting plugins that will help. Or you can modify one of them to meet your text format.

    Kevin

  • arnorbldarnorbld Posts: 123Questions: 23Answers: 1

    Hi,

    Thank you for the quick response! Tried it and it didn't work. Will have to get back to this later and do more investigation on this :)

  • arnorbldarnorbld Posts: 123Questions: 23Answers: 1

    Hi,

    So the default sort order looks like this:

    The two folders in the box should be at the bottom, the rest is correct.

    With the plugin it becomes very strange:

    I'm not really sure what it's sorting on and how...

    I'm leaving this for another time :)

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited August 2021

    Please provide a test case with an example of your data so we can help.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    It may require modifying one of the sorting plugins to match you data structure.

    Kevin

  • allanallan Posts: 63,681Questions: 1Answers: 10,498 Site admin

    Agreed - I would have suggested the natural sort plugin here as well, but perhaps it isn't coping with the more complex data structure you have there.

    They look like links you have there, are you using the natural-nohtml type?

    Allan

  • arnorbldarnorbld Posts: 123Questions: 23Answers: 1

    Hi Alan,

    Thanks guys for the responses. Using the nohtml I think has fixed this!

Sign In or Register to comment.