Search code examples
javascriptjquerytablesorter

Tablesorters addparse gives "undefined is not a function "


Tablesorter isn't acception .addParser somehow. I get the error "undefined is not a function". This is my code:

 $('mytable').tablesorter({
    sortList: [[0,0]],
    sortRestart: true,
    initialized: function(table) {
        var currentTable = $(table);
        var startcol = currentTable.data("startcol");
        if (startcol) {
            var sorting = [[startcol, 0]];
            currentTable.trigger("sorton", [sorting]);
        }
    },
    headers:
    {
        4: { sorter: 'customparse' },
        5: { sorter: 'customparse' }
    }
}).addParser({
    id: 'customparse',
    is: function (s) {
        return false;
    },
    format: function (s) {
        console.log(s);
        return s.replace(/\s+/g, '').replace(/,/g, '.');
    },
    type: 'numeric'
});

I found some other related questions and cant find my issue.. I've doubble check that jQuery isnt included twice. It works fine without addPareser even thought the jQuery version Im using is 1.11. But I tried updating to version 2.1 but no change..

Am I initiating it wrong? what am I doing wrong..


Solution

  • To add a parser, you need to use $.tablesorter.addParser(). You cannot access the method from a jQuery object, as you're trying to do.