Remove prefix of column sort not working

Remove prefix of column sort not working

jdoensjdoens Posts: 18Questions: 4Answers: 0
edited December 2017 in Free community support

I am trying to use a custom sort function to remove the first few characters of a column to sort (while still showing its original text). For some reason it won't work. I feel it might be related to my regex, however, I've tested the regex elsewhere and it properly returns what I'm looking for. I am also using another sort function which I added later (even after the other wasn't working) and this other sort function works fine. Any insight or help would be immensely appreciated.

I'm setting the sort function for only one particular column:

        "columns": [
            {
                "data": "test",
                "render": function (data) {
                    return '<b>' + data + '</b>';
                },
                "type": 'removethem', targets: 0
            },
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "removethem-pre": function (a) {
        return a.replace(/^ABC-|^GHI-|^XYZ-/i, "");
    },

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

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

jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "currency-pre": function (a) {
        a = (a === "-") ? 0 : a.replace(/[^\d\-\.]/g, "");
        return parseFloat(a);
    },

    "currency-asc": function (a, b) {
        return a - b;
    },

    "currency-desc": function (a, b) {
        return b - a;
    }
});
This discussion has been closed.