I have some code at the moment that hides a row that is deleted and then removes it using the .remove() function.
However I'm having difficulty is making it remain "deleted" as every time I refresh the table sorted pager plugin or the filter plugin addon I'm using.. the deleted rows re-appear as they are of course cached.
Current code just simple with widget update at the moment
$('.deleteMAP').live("click", function(){
$(this).closest('tr').css('fast', function() {
$(this).remove();
$(".tablesorter").trigger("update");
$(".tablesorter").trigger("applyWidgets");
});
})
Is there anyway to remove the "row" from both the cache of the pager plugin and also the tablesorter plugin so that when I "update" the table to reflect the fact a row has been removed they don't re-appear back from the dead via the cache!
Things goes tricky when you use both tablesorterpager and tablesorterfilter plugins - solution with:
works only for pager, filter has another cache. I've looking for solution for almost 2 hours, at last i've written something like this:
I'm deleting row which has rel attribute the same as input#removeThisID value.
Now it's time to modify tablesorterfilter plugin. In doFilter function, find lines:
and replace these with:
that's all...
regards form Poland :)
Better to use table.splice(index, 1); than delete( table[index] );! "Delete" do just empty element of array, but not deleted completely. Sorry for my English! =)
I found a solution that worked for me:
Put this after the place where you've edited the table.
Please have a look at Motties tablesorter fork. He made an example for adding/removing rows when using tablesorter and pager plugin. http://mottie.github.com/tablesorter/docs/example-pager.html
Jitter solution was almost working for me although a line was missing for update (see code below). I've extended the code to allow insert new TR's in table.
I've been playing around and it works for me under FFox, didn't check on IExplorer. Anyway there's a bug I couldn't fix yet: If you add a new TR and then you try to delete it it won't be deleted from table :(
And you can use is as follows:
Add new TR with complex HTML in it:
Remove any TR:
My simplified sample table:
After some tinkering around with this problem I conclude the problems arise from the combined use of jQuery Tablesorter + jQuery TablesorterPager. With out the pager removing the row and doing and "update" is enough.
When you also include the pager it gets much more difficult to do this right (as how you noticed correctly there are some caching issues).
But the main reason for your problem is that jQuery Tablesorter isn't thought to be used for tables which you intent to modify (in the sense of adding/removing rows). And this applies even more when you additionally use TablesorterPager. Just reread the description of jQuery Tablesorter
A clear and concise field of application for TableSorter. It doesn't even mention ajax, edit, remove, append, ..... or similar terms on the page. It is only for sorting a static table.
So the actual solution is.... start looking for another jQuery "Table" plugin which was built from the start with the intention/possibility that the table can be modified. And which supports this by default (removing, adding, ....)
Ok nonetheless here is the solution for:
jQuery Tablesorter + TablesorterPager remove rows (TR)
Quick copy-paste of the javascript source-code (HTML based on TablesorterPager example)
I made a testpage for you with my solution (click the red TD's == removing that row).
http://jsbin.com/uburo (http://jsbin.com/uburo/edit for the source)
If question remain on how/why/.... Comment