Sorting legal and code version style numbering

Sorting legal and code version style numbering

silkspinsilkspin Posts: 152Questions: 34Answers: 5

I'm trying to sort legal and code version style numbering. i.e. 2, 2.1, 2.2 .... 2.9, 2.10, 2.11. However normal sorting would put 2.11 after 2.1 so 2.2 wouldn't appear until after the last 2.1.x.

It would also be good to be able to do this with a mixture of numbers and alphabetical characters like with legal documents. i.e. 1.2.a, 1.2.b.

I've tried using the natural.js plugin but it doesn't help in this case. Are there any other recommended plugins or maybe any changes that can be made to natural.js? Thanks.

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited July 2020 Answer ✓

    I believe your first example requires the "chapter" sorting plug-in;
    https://datatables.net/plug-ins/sorting/chapter

    but I can't help with your other example. I would have guessed that the "natural" plug-in would deal with 1.2.a, 1.2.b. etc.

    EDIT: sort plug-ins will have no effect on server-side processing, where it is up to your own server-side script to provide the sort functionality.

    @Allan, @Colin, this point is often not spelled out in the relevant docs (not limited to sort plug-ins) unless i'm missing something.

  • silkspinsilkspin Posts: 152Questions: 34Answers: 5

    Thanks Tangerine!

    Chapter.js works with both scenarios. I'm not intending using server side processing in my case, but it's good to know if I ever need to consider it.

    I've done quite a lot of testing in natural.js and it doesn't handle that particular alphanumeric style of numbering once you get into double digits.

    This was the legal style I needed to sort…

    1, 1.1, 1.1.a, 1.1.b, 1.1.c …. 1.10, 1.10.a, 1.10.b, 1.11, 1.11.a, 1.11.b, 1.12

    What happens with natural.js is…

    1, 1.1.a, 1.1.b, 1.1.c, 1.10.a, 1.10.b, 1.11.a, 1.11.b, 1.1, 1.10, 1.11, 1.12

    That's not important now you've recommended chapter.js, but hopefully it will be helpful to others.

This discussion has been closed.