DOM ordering using plugin dom-text-numeric sorts lexiconically instead of by input value

DOM ordering using plugin dom-text-numeric sorts lexiconically instead of by input value

MoneMone Posts: 1Questions: 1Answers: 0

I was upgrading datatables from 1.13.7 to latest 2.2.2, and noticed that the DOM ordering plugin dom-text-numeric is no longer sorting correctly. Instead of sorting by value, the order is now seems to be lexiconically, e.g. value "10" is ordered before value "2".

The error can be viewed in the live example at the site:
https://datatables.net/examples/plug-ins/dom_sort.html

Setting the following values in the Age column: 9, 100, 11 and sorting ascending by the same column will result in the following sort order:
100
11
9

Best regards

Answers

  • kthorngrenkthorngren Posts: 21,912Questions: 26Answers: 5,063

    It looks like the columns.type is set to html not num for that column. Not sure why the change but @allan might be able to tell us why. This is from the Datatable's settings object for the second column:

    {
        "idx": 1,
        "aDataSort": [
            1
        ],
        "asSorting": [
            "asc",
            "desc",
            ""
        ],
    ...
        "sType": "html",
    ....
    }
    

    Setting columns.type to num works around the issue. See this test case:
    https://live.datatables.net/pisixaqe/1/edit

    Kevin

Sign In or Register to comment.