Mottie / tablesorter

Github fork of Christian Bach's tablesorter plugin + awesomeness ~
https://mottie.github.io/tablesorter/docs/
2.61k stars 754 forks source link

Adding/Removing widgets from table #112

Closed thezoggy closed 12 years ago

thezoggy commented 12 years ago

say I have a table, with:

widgets: ["zebra", "filter", "resizable", "columns", "stickyHeaders"],

then i have a button where I do:

 $("table").data("tablesorter").widgets = ["zebra"]; 
 $("table").trigger("applyWidgets");

should that not remove all widgets except zebra?

Mottie commented 12 years ago

That is referring to tablesorter version 3 that I sent you. In that version, the widgets are set in the config:

$('table').data('tablesorter').config.widgets = ['zebra']; // v3 only
$('table').trigger('applyWidgets');

In the current version, use:

$('table')[0].config.widgets = ['zebra'];
 $('table').trigger('applyWidgets');

(updated) or as you said, use:

$('table').data('tablesorter').widgets = ['zebra'];
$('table').trigger('applyWidgets');
Mottie commented 12 years ago

Actually, I was wrong.

$('table').data('tablesorter').widgets = ['zebra'];

Will work, leave out the .config... see this demo, I've added this example to my last comment.

thezoggy commented 12 years ago

thanks, i should have more time later today to play around with stuff

Mottie commented 12 years ago

I'm working on adding a remove function for each widget... they won't work with older versions of tablesorter, but in the upcoming version you will be able to trigger a refreshWidgets event which will remove unused widgets and update selected widgets. With an additional flag, the same triggered even will remove all widgets and reinitialize the selected widgets.

// removed unused widgets and update current widgets
$('table').trigger('refreshWidgets');

or, send a true flag along with the event:

// remove ALL widgets, then reinitialized current widgets
// current widgets are found in the `widgets` option
$('table').trigger('refreshWidgets', true);
Mottie commented 12 years ago

Ok, version 2.4 is up and running... see the refreshWIdgets documentation. It is used the same as I mentioned above.