Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger("update") causes table contents to be deleted #217

Closed
adamthehutt opened this issue Jan 18, 2013 · 8 comments
Closed

trigger("update") causes table contents to be deleted #217

adamthehutt opened this issue Jan 18, 2013 · 8 comments

Comments

@adamthehutt
Copy link

Hi,

I'm using the latest version of tablesorter. After deleting a row from a table, I'm calling $("table").trigger("update"). Every time I call that, however, the entire contents of the table are deleted, leaving only the opening and closing

tags.

What's even stranger is that the same thing happens when I call trigger("update") even without removing any rows (i.e. immediately after initializing the tablesorter).

I've been banging my head against this wall for a while. Probably I'm doing something stupid, but any insights would be greatly appreciated.

Thanks,
Adam

@Mottie
Copy link
Owner

Mottie commented Jan 18, 2013

Hi @adamthehutt!

Maybe this demo will help clarify any issues you might be having?

$('.remove').click(function(){
    $(this).closest('tr').remove();
    $('table').trigger('update');
});

If you are using the pager plugin as well, then I would suggest making sure the pager removeRows option is set to false and then check out this demo.

@adamthehutt
Copy link
Author

Thanks, Mottie. That helped me debug the issue.

Turns out the problem is that my site also includes the Prototype library, so I'm using jQuery.noconflict() to assign the $() function a different name. When I remove Prototype, everything works correctly.

So, my guess is that something in the tablesorter plugin isn't wrapped in a way that accommodates noconflict(). What's weird is that tablesorter otherwise works perfectly. It's just when I trigger an update that it breaks. Any ideas?

Thanks again for your help.

@adamthehutt
Copy link
Author

UPDATE: I found this discussion on StackOverflow:
http://stackoverflow.com/questions/11070310/using-jquery-tablesorter-with-prototype

Looks like the problem is actually with Prototype, not Tablesorter.

@Mottie
Copy link
Owner

Mottie commented Jan 18, 2013

Hmm, maybe I should add another trigger along with "update", something like "tsUpdate"? Normally, I would namespace the event (update.tablesorter), but I'm not sure if prototype would ignore it or not.

Anyway, for a quick fix, update line 706 from this:

.bind("update", function(e, resort, callback) {

to this:

.bind("update tsUpdate", function(e, resort, callback) {

then just use:

$('table').trigger('tsUpdate');

@adamthehutt
Copy link
Author

Thanks. That would work, although I'm trying to avoid making changes that will be reverted if I upgrade to a newer version of Tablesorter in the future. (My problem, not yours... I think I have another, cruder workaround in the meantime.)

I like the idea of creating an alias trigger for future versions. Maybe you could use "updateContents" or "updateRows" for consistency (since the other events aren't namespaced). Just a suggestion (admittedly an anal one).

@Mottie
Copy link
Owner

Mottie commented Jan 18, 2013

Hmm, I do like "updateRows" better. I'll add it in the next update! :)

@adamthehutt
Copy link
Author

That sounds great! Thanks for being so responsive. I'll go ahead and modify my local copy of the tablesorter plugin to use updateRows in the meantime.

@Mottie
Copy link
Owner

Mottie commented Jan 18, 2013

As soon as I figure out how to register a plugin "correctly" with the jquery plugin registry, I'll push the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants