diff --git a/docs/example-widgets.html b/docs/example-widgets.html index 50796dbe..288187e6 100644 --- a/docs/example-widgets.html +++ b/docs/example-widgets.html @@ -28,9 +28,11 @@ // give the widget an id id: "repeatHeaders", - - // format is called when the on init and when a sorting has finished - format: function(table) { + options: { + rowsToSkip : 4 + }, + // format is called on init and when a sorting has finished + format: function(table, c, wo) { var h, i, skip; // cache and collect all TH headers if (!this.headers) { @@ -44,7 +46,7 @@ $(table).find("tr.repeated-header").remove(); // number of rows to skip - skip = 4; + skip = wo && wo.rowsToSkip || 4; // loop all tr elements and insert a copy of the "headers" for (i = skip; i < table.tBodies[0].rows.length; i += (skip + 1)) { @@ -84,277 +86,120 @@
+ +
+ Notes about the addWidget template below: + +
+ +

addWidget Template

+
+
// addWidget Template
+// *******************
+// parameters:
+// table = table object (DOM)
+// config = config object (from table.config)
+// widgetOptions = all widget options (from table.config.widgetOptions)
+$.tablesorter.addWidget({
+  id: 'myWidget',
+  // widget options (added v2.8) - added to table.config.widgetOptions
+  options: {
+    myWidget_option1 : 'setting1',
+    myWidget_option2 : 'setting2'
+  },
+  // The init function (added v2.0.28) is called only after tablesorter has
+  // initialized, but before initial sort & before any of the widgets are applied.
+  init: function(table, thisWidget, config, widgetOptions){
+    // widget initialization code - this is only *RUN ONCE*
+    // but in this example, only the format function is called to from here
+    // to keep the widget backwards compatible with the original tablesorter
+    thisWidget.format(table, config, widgetOptions, true);
+  },
+  format: function(table, config, widgetOptions, initFlag) {
+    // widget code to apply to the table *AFTER EACH SORT*
+    // the initFlag is true when this format is called from the init
+    // function above otherwise initFlag is undefined
+    // * see the saveSort widget for a full example *
+  },
+  remove: function(table, config, widgetOptions){
+    // do what ever needs to be done to remove stuff added by your widget
+    // unbind events, restore hidden content, etc.
+  }
+});
+
+

Demo

- - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +
NameMajorSexEnglishJapaneseCalculusGeometry
NameMajorSexEnglishJapaneseCalculusGeometry
NameMajorSexEnglishJapaneseCalculusGeometry
NameMajorSexEnglishJapaneseCalculusGeometry
Student01Languagesmale80707580
Student02Mathematicsmale908810090
Student03Languagesfemale85958085
Student04Languagesmale6055100100
Student05Languagesfemale68809580
Student06Mathematicsmale1009910090
Student07Mathematicsmale85689090
Student08Languagesmale100909085
Student09Mathematicsmale80506575
Student10Languagesmale8510010090
Student11Languagesmale8685100100
Student12Mathematicsfemale100757085
Student13Languagesfemale1008010090
Student14Languagesfemale50455590
Student15Languagesmale953510090
Student16Languagesfemale100503070
Student17Languagesfemale801005565
Student18Mathematicsmale30495575
Student19Languagesmale68908870
Student20Mathematicsmale40454080
Student21Languagesmale5045100100
Student22Mathematicsmale1009910090
Student23Languagesfemale85808080
Student24Languagesfemale100911382
Student12Mathematicsfemale100757085
Student13Languagesfemale1008010090
Student14Languagesfemale50455590
Student15Languagesmale953510090
Student16Languagesfemale100503070
Student17Languagesfemale801005565
Student18Mathematicsmale30495575
Student19Languagesmale68908870
Student20Mathematicsmale40454080
Student21Languagesmale5045100100
Student22Mathematicsmale1009910090
Student23Languagesfemale85808080
Student01Languagesmale80707580
Student02Mathematicsmale908810090
Student03Languagesfemale85958085
Student04Languagesmale6055100100
Student05Languagesfemale68809580
Student06Mathematicsmale1009910090
Student07Mathematicsmale85689090
Student08Languagesmale100909085
Student09Mathematicsmale80506575
Student10Languagesmale8510010090
Student11Languagesmale8685100100
Student24Languagesfemale100911382
-

Javascript

-

Add Widget Template

-
-
// addWidget Template
-// *******************
-$.tablesorter.addWidget({
-	id: 'myWidget',
-	// The init function (added in v2.0.28) is called only after tablesorter has
-	// initialized, but before initial sort & before any of the widgets are applied.
-	init: function(table, allWidgets, thisWidget){
-		// widget initialization code - this is only *RUN ONCE*
-		// but in this example, only the format function is called to from here
-		// to keep the widget backwards compatible with the original tablesorter
-		thisWidget.format(table, true);
-	},
-	format: function(table, initFlag) {
-		// widget code to apply to the table *AFTER EACH SORT*
-		// the initFlag is true when this format is called from the init
-		// function above otherwise initFlag is undefined
-		// * see the saveSort widget for a full example *
-	}
-});
-
- -

Repeat Headers Widget Code

+

Repeat Headers Widget


diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js
index aaf7a717..18c24cef 100644
--- a/js/jquery.tablesorter.js
+++ b/js/jquery.tablesorter.js
@@ -1097,10 +1097,11 @@
 				for (i = 0; i < l; i++) {
 					w = ts.getWidgetById(ws[i]);
 					if ( w ) {
-						if (init === true && w.hasOwnProperty('init')) {
-							w.init(table, w, c, wo);
+						if (init) {
+							if (w.hasOwnProperty('options')) { $.extend( true, wo, w.options ); }
+							if (w.hasOwnProperty('init')) { w.init(table, w, c, wo); }
 						} else if (!init && w.hasOwnProperty('format')) {
-							w.format(table, c, wo);
+							w.format(table, c, wo, false);
 						}
 					}
 				}
diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js
index 2546b296..c70e18f5 100644
--- a/js/jquery.tablesorter.widgets.js
+++ b/js/jquery.tablesorter.widgets.js
@@ -977,14 +977,15 @@ $.tablesorter.resizableReset = function(table){
 // **************************
 $.tablesorter.addWidget({
 	id: 'saveSort',
-	init: function(table, thisWidget){
+	init: function(table, thisWidget, c, wo){
 		// run widget format before all other widgets are applied to the table
-		thisWidget.format(table, true);
+		thisWidget.format(table, c, wo, true);
 	},
-	format: function(table, init){
+	format: function(table, c, wo, init){
+		// redefining c & wo for backwards compatibility
+		c = table.config;
+		wo = c.widgetOptions;
 		var sl, time, $t = $(table),
-			c = table.config,
-			wo = c.widgetOptions,
 			ss = wo.saveSort !== false, // make saveSort active/inactive; default to true
 			sortList = { "sortList" : c.sortList };
 		if (c.debug){