Comma Separated Index

Comma Separated Index

edoardo.donatiedoardo.donati Posts: 3Questions: 1Answers: 0

Hi everybody, I have the following problem with the datatables editor :
I have a table with the very first column containing a comma separated index like 1.1, 2.1, 3.1 etc.

Everything works fine until two digits numbers (like 10) comes along.
I tried a lot of sorting plug-ins but nothing seems to work.

Can anybody help ?

Edoardo

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,833Questions: 1Answers: 10,518 Site admin

    Hi Edoardo,

    Could you post a full example showing the data you are working with and how you expect it to sort? DataTables will string sort comma separated values which is why you will have issues with numbers such as 10.

    It might be that the natural sorting plug-in is the way to go here.

    Allan

  • edoardo.donatiedoardo.donati Posts: 3Questions: 1Answers: 0
    edited December 2016

    Alright, this is an example.

    As you can see I have a sequential number as first column.
    In the attempt of "grouping" the rows, we thought to use this kind of index like :

    1
    1.1
    2
    2.1

    and so on.

    Unfortunately when 10, 11 or 12 arrive the sorting is all messed up.

    Sorting plug-ins doesn't seem to have any effect at all.
    I tried :

            columns: [
                { data: "funzionalita.ProgFunc", editField: "funzionalita.ProgFunc", width:"5%", type:"natural-nohtml"},
    

    and

        columnDefs: [
           { type: 'natural-nohtml', targets: 0 }
         ],
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,833Questions: 1Answers: 10,518 Site admin
    Answer ✓

    Numbers like that should be automatically detected. Only if you had a comma in there would there be a problem.

    If you link to a page or example showing the issue I'd be happy to take a look and see why that isn't working for you.

    Grouping using numbers like that is a good idea, and I've seen it used and working before.

    Allan

  • edoardo.donatiedoardo.donati Posts: 3Questions: 1Answers: 0

    Natural sorting did work in the end, I had to add an hidden column containing IDs from the DB and then change the target in the columnsDef.

    Thank you very much for your help Allan.

This discussion has been closed.