diff --git a/docs/example-apply-widget.html b/docs/example-apply-widget.html index 99bffb5c..3d7ad153 100644 --- a/docs/example-apply-widget.html +++ b/docs/example-apply-widget.html @@ -16,26 +16,35 @@ + @@ -48,65 +57,30 @@

- NOTE! Click on [ Apply Widget Id ], then sort the table a few times... then click on [ Apply Widgets ] and sort again (these methods are part of the original plugin). + NOTE! +

As of v2.24.7, using the applyWidgetId will now add the widget to the widgets options, so you will no longer notice any difference between the two methods. The difference is:

+

Demo


-
+
(columns & sort)
+ (columns & zebra)
+ (add 'zebra' to table.config.widgets then trigger applyWidgets method) - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +
First NameLast NameAgeTotalDiscountDate
First NameLast NameAgeTotalDiscountDate
PeterParker28$9.9920%Jul 6, 2006 8:14 AM
JohnHood33$19.9925%Dec 10, 2002 5:14 AM
ClarkKent18$15.8944%Jan 12, 2003 11:14 AM
BruceAlmighty45$153.1944%Jan 18, 2001 9:12 AM
BruceEvans22$13.1911%Jan 18, 2007 9:12 AM
PeterParker28$9.9920%Jul 6, 2006 8:14 AM
JohnHood33$19.9925%Dec 10, 2002 5:14 AM
ClarkKent18$15.8944%Jan 12, 2003 11:14 AM
BruceAlmighty45$153.1944%Jan 18, 2001 9:12 AM
BruceEvans22$13.1911%Jan 18, 2007 9:12 AM
@@ -128,4 +102,3 @@ - diff --git a/docs/index.html b/docs/index.html index 48a4733e..e3ef4341 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5071,15 +5071,20 @@ $.tablesorter.updateCell( config, $cell, resort, callback ); - Apply the selected widget to the table, but the widget will not continue to be applied after each sort. See the example, it's easier than describing it. + Apply the selected widget to the table, but the widget will not continue to be applied after each sort. See the example, it's easier than describing it (v2.24.7).
+

In v2.24.7, this method ensures that the widget initialization code is executed as well as the format function. So now a widget that was not previously initialized or had been previously removed, can be reapplied.

+

Only one widget can be applied at a time using this method.

+

Direct method:

+
$.tablesorter.applyWidgetId( $( 'table' ), 'zebra' );
+

Triggered event method:

$(function(){
   // initialize tablesorter without the widget
   $("table").tablesorter();
 
   // click a button to apply the zebra striping
   $("button").click(function(){
-    $('table').trigger('applyWidgetId', ['zebra']);
+    $('table').trigger('applyWidgetId', 'zebra');
     return false;
   });
 
@@ -5092,18 +5097,50 @@ $.tablesorter.updateCell( config, $cell, resort, callback );
Apply the set widgets to the table (v2.16.0).
- This method can be used after a table has been initialized, but it won't work unless you update the configuration settings. See the example, it's easier than describing it. -
// Update the list of widgets to apply to the table (add or remove)
-// $("table").data("tablesorter").widgets = ["zebra"]; // works the same as
-$("table")[0].config.widgets = ["zebra"];
-
-// This method applies the widget - no need to keep updating
+						

This method only updates the widgets listed in the table.config.widgets option.

+
// This method applies the widgets already added to tablesorter
 $('table').trigger('applyWidgets');
+
+ Use this method can be used to add multiple widgets to the table. +
var $table = $( 'table' );
+$table[0].config.widgets = [ 'zebra', 'columns' ];
+$table.trigger('applyWidgets');
 
Example + + + Remove the named widget from the table (v2.24.7). +
+

This method will remove the named widget(s) from the table.

+

Direct method:

+
$.tablesorter.removeWidget( $( 'table' ), widget );
+

Triggered event method:

+
$( 'table' ).trigger( 'removeWidget', widget );
+

The widget parameter can be used as follows:

+
    +
  • Single widget name - string +
    // only remove zebra widget
    +$( 'table' ).trigger( 'removeWidget', 'zebra' );
    +
  • +
  • Multiple widgets names - array or string (space or comma separated) +
    // remove multiple widgets (the below methods are all equivalent)
    +$( 'table' ).trigger( 'removeWidget', 'zebra columns' );
    +$( 'table' ).trigger( 'removeWidget', 'zebra, columns' );
    +$( 'table' ).trigger( 'removeWidget', [ 'zebra', 'columns' ] );
    +
  • +
  • true - boolean (removes all widgets; passing false does nothing) +
    // remove all widgets
    +$( 'table' ).trigger( 'removeWidget', true );
    +
  • +
+
+ + Example + + Use this method to remove tablesorter from the table (v2.3.2; v2.16). diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index eb8cc478..2d67c89d 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -405,6 +405,10 @@ e.stopPropagation(); ts.refreshWidgets( this, all, dontapply ); }) + .bind( 'removeWidget' + namespace, function( e, name, refreshing ) { + e.stopPropagation(); + ts.removeWidget( this, name, refreshing ); + }) .bind( 'destroy' + namespace, function( e, removeClasses, callback ) { e.stopPropagation(); ts.destroy( this, removeClasses, callback ); @@ -2344,10 +2348,11 @@ } // remove widget added rows, just in case $h.find( 'tr' ).not( $r ).remove(); - // disable tablesorter + // disable tablesorter - not using .unbind( namespace ) because namespacing was + // added in jQuery v1.4.3 - see http://api.jquery.com/event.namespace/ events = 'sortReset update updateRows updateAll updateHeaders updateCell addRows updateComplete sorton ' + - 'appendCache updateCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave keypress ' + - 'sortBegin sortEnd resetToLoadState '.split( ' ' ) + 'appendCache updateCache applyWidgetId applyWidgets refreshWidgets removeWidget destroy mouseup mouseleave ' + + 'keypress sortBegin sortEnd resetToLoadState '.split( ' ' ) .join( c.namespace + ' ' ); $t .removeData( 'tablesorter' )