Mottie/tablesorter

Tablesorter widget.js wrong loop count

hempel opened this issue · 1 comments

Hey all,

when i tried to setup the latest version (2.14.2), i always got an error:

TypeError: c.cache[tbodyIndex].normalized[rowIndex] is undefined
cached = c.cache[tbodyIndex].normalized[rowIndex][columnIndex];
jquery.tablesorter.widgets.js (Line 858).

The error showed up, when i tried to use Tablesorter with TablesorterPager and activated filter widget. I tried to filter the first column with "Bu" and after seeing the results i tried to expand the filter to "Buc". It is reproducable, when you open the docs from current download-archive "docs/example-pager-filtered.html". Try to filter the first column (name) with "Sti" (typo for "Students"). Then, after the results (no results because of typo) are shown, just press backspace, that the current filter is "St". Then the error rises up.

I inspected the code and could see, that the "fixedHeight" property in pagerOptions adds a new row to your table to simulate the full length table.
The problem is, that the for-loop in jquery.tablesorter.widgets.js (line 842) loops through all lines in the table. The new added tr.pagerSavedHeightSpacer can't be found in the cached table.

So i think that the error should rise every time you have a "shortened" table and try to change the filter value.

Possible solution:
Change row 827 from
$rows = $tbody.children('tr').not('.' + c.cssChildRow).not('.group-header');

to
$rows = $tbody.children('tr').not('.' + c.cssChildRow).not('.group-header').not(c.selectorRemove);

Hi @hempel!

Thanks for working this issue out, I'll have a look at it and hopefully have it fixed in the next update!