5 Answers
5

One way we managed to get around it is by starting off with a dummy <tr> regardless of whether the table has any data or not, and then hiding it via js on document load.
–
Val RedchenkoFeb 8 '12 at 19:44

I just encountered this error so I thought I'd post a response in case anyone else has trouble with it later.

Although the above answer doesn't mention it, I was able to replicate the error by first instantiating tablesorter() and then triggering a sort request.

This order of events would be necessary when appending or replacing existing table data with new data via AJAX or otherwise like so:

// populate our table body with rows
$("#myTable tbody").html(json.tbody);
// let the sorting plugin know that we made a update
$("#myTable").trigger("update");
// set sorting column and direction, this will sort on the first and third column
var sorting = [[2,1],[0,0]];
// sort
$("#myTable").trigger("sorton",[sorting]);

The combination of the "update" and the "sorton" event seems to be triggering the error. By the time the "sorton" event is handled the DOM hasn't been assigned the table.config.parsers - thus the error.

The fix is to wrap the "sorton" event handling in a 1 millisecond timeout.

Replace the existing "sorton" bind in jquery.tablesorter.js (line ~803) with the following:

Another answer just in case anyone ever runs into the same scenario I did. Apparently table sorter sometimes likes to have a matching number of empty <td> elements (the same as your header elements) inside the empty <tr>. My partial example is below

I tried some of the answers above but they didn't help in every page we were using tablesorter. Primary reason I figured for error is that c=sortList[i][0] is undefined either because we have an empty TR or we don't same number of TD as that of TH.

I had 8 TH/TD in case I have table data and 8 TH & single TD in case I have nothing to show. I managed to check if I have no table data then don't call tablesorter to sort on specific columns which doesn't exist. This did the trick. Might help someone with similar scenario