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

ajax update with different thead? #262

Closed
designosis opened this issue Mar 22, 2013 · 2 comments
Closed

ajax update with different thead? #262

designosis opened this issue Mar 22, 2013 · 2 comments

Comments

@designosis
Copy link

This began as an issue, but I came up with a solution in the process of writing it down. Someone might find this useful in your "empty table" example http://mottie.github.com/tablesorter/docs/example-empty-table.html ...

If you are replacing the <tbody> content, the given example is perfect. However, if you want to dynamically replace the <thead> as well, you need to do something like this:

$('#mytable').trigger('destroy').html(' new thead and tbody ').tablesorter({...});

One more thing to note: Parsers will need to be re-applied, as 'destroy' destroys them as well.

Thanks Mottie for the amazing work!

@Mottie
Copy link
Owner

Mottie commented Mar 22, 2013

Hi neokio!

Thanks for the compliment! :)

Hmm, maybe I should add a new "fullUpdate" method or add some flag to make the existing "update" method include the thead.

I just answered a similar question on StackOverflow and provided this code:

// initialisation
var initOptions = {
  theme: 'blue',
  sortList: [[2,1],[0,0]]
};
$("table").tablesorter(initOptions);

Then after the ajax update, use:

// Remove tablesorter and all classes
// false in the destroy method means leave the "tablesorter" and "tablesorter-{theme}" class names alone
$("table").trigger("destroy", [false, function(){
  // callback after the destroy method

  // modify the table here
  $('table thead').html( '<tr>' + headers + '</tr>' );
  $('table tbody').html( data );

  // reinitialize the plugin
  $("table").tablesorter(initOptions);
}]);

*Note: You can't modify the thead before calling the destroy method because the destroy method will restore the headers to the way they were before the plugin was initialized (data is saved in table.config.headerContent)

@Mottie
Copy link
Owner

Mottie commented Mar 27, 2013

Hi @neokio!

I just pushed out v2.8.0 which includes a new updateAll method. Check out the demo.

@Mottie Mottie closed this as completed Mar 27, 2013
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