diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 98f6f713..e992e5f0 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -170,7 +170,8 @@ function buildParserCache(table) { var c = table.config, - tb = c.$tbodies, + // update table bodies in case we start with an empty table + tb = c.$tbodies = c.$table.children('tbody:not(.' + c.cssInfoBlock + ')'), rows, list, l, i, h, ch, p, parsersDebug = ""; if ( tb.length === 0) { return c.debug ? log('*Empty table!* Not building a parser cache') : ''; @@ -322,6 +323,7 @@ function computeThIndexes(t) { var matrix = [], lookup = {}, + cols = 0, // determine the number of columns trs = $(t).find('thead:eq(0), tfoot').children('tr'), // children tr in tfoot - see issue #196 i, j, k, l, c, cells, rowIndex, cellId, rowSpan, colSpan, firstAvailCol, matrixrow; for (i = 0; i < trs.length; i++) { @@ -343,6 +345,7 @@ } } lookup[cellId] = firstAvailCol; + cols = Math.max(firstAvailCol, cols); // add data-column $(c).attr({ 'data-column' : firstAvailCol }); // 'data-row' : rowIndex for (k = rowIndex; k < rowIndex + rowSpan; k++) { @@ -356,6 +359,7 @@ } } } + t.config.columns = cols; // may not be accurate if # header columns !== # tbody columns return lookup; } @@ -448,7 +452,7 @@ var $c, c = table.config, $cg = $('