0

I am trying to create a custom ordering system to sort the rows with a special alpha numberic format

The data in the column is a distance call out such as "1.79 mi" , "10.21 mi" or "9.21 mi"

My issue is that when I sort desc it will put the 9.21 after the 10.21.

I am using the following code.

aaSorting = [[3,'desc']];

I am assuming I have to create special definitions using aoColumnDefs and sType but I cant seem to figure them out.

1 Answer 1

1

you can add your own plugin for sorting.

check other examples https://datatables.net/plug-ins/sorting/

jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "distance-pre": function (a) {
        var x = (a == "-") ? 0 : a.replace(/mi/, "");
        return parseFloat(x);
    },

    "distance-asc": function (a, b) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "distance-desc": function (a, b) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
});

Usage

type: 'distance'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.