Error with empty table and pager widget
Prestaplugins opened this issue · 6 comments
Hello,
Sorry if the following bug has already been reported...
I'm trying to create a table with tablesorter, pager and filter widget.
My table needs to be empty at start, then I add rows with javascript.
I made a simple test following the examples.
Example 1 : http://www.prestaplugins.com/test/tablesorter/example1.html
If you click "Add row", you can see an error is thrown :
TypeError: c.cache[tbdy] is undefined
It's the same if you create a table witch is not empty at start, then you remove all rows by clicking "Remove row" and then you try to add a new one.
Example 2 : http://www.prestaplugins.com/test/tablesorter/example2.html
So I tried something. When I create a row, if it's the first one, I restore the pager widget AFTER the first line is added.
And if I remove the last row, I destroy the pager widget.
It seems working... but there's a new issue.
If my page default size is 10 rows, then after removing all, if I add a lot, the 12th appears on the first page with all the next ones until 20, so there is more than 10 rows in my page. Then at 30th row, all rows from 12 to 30 disappears but those from 20 to 30 are displayed...
Example 3 : remove the line, then click on Add many times (more than 12).
http://www.prestaplugins.com/test/tablesorter/example3.html
I worked on this all the day trying to find a solution, I'm so tired...
You're my last hope, please HELP...
Last thing... I don't understand why the filter doesn't appears even when my table is not empty at start, like in example 2. But I didn't investigate on this...
Hi @Patanock!
That looks like it's a bug in the addRows
method... it expects the cache to not be empty. I'll have this issue fixed in the next update; but until then I would suggest using the update
method (updated demo)
function addLine() {
i++;
line = $('<tr><td>'+i+'</td><td>'+i+'</td></tr>');
$('.tablesorter tbody').append(line).trigger("update");
}
And just using "update" should take care of all 3 problems that you've described.
Edit: Oh, and the filter row is made to hide when there is no content to filter.
Hi @Mottie !
OMG Thanks !! It seems to work, but I can't believe that I didn't test it. I thought I tried all the combinations.
So much time lost... :(
About the filter, why doesn't it appear on example2 ? There's content.
Or how to make it appears at start even if the table is empty, or at least after the first row is added ?
Example 2 isn't working because of the addRows
bug... try adding rows in the demo I shared above... hmm, but I guess it doesn't hide the filter row if you delete all the rows after adding some. I'll fix that too.
Oops, forgot to fix the filter row hiding... ugh
Hi @Mottie !
I tried your demo at : http://jsfiddle.net/Mottie/abkNM/1675/
Everything seems ok except that the Zebra widget doesn't work on new lines.
Is that normal ?
I need to add this, after update to make it work :
$('.tablesorter').trigger('refreshWidgets', true, false);
Hi @Patanock!
Yeah, sorry. With the holidays and going out of town I haven't had a chance to finish updates and push out the next version. Once that is done, there is already a fix in place that will solve that issue (without needing to trigger refreshWidgets
). Sorry for the inconvenience!