From c4eb30992a4ff9755c57a85f95526eb1d518ae82 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Wed, 15 Mar 2017 12:00:29 -0500 Subject: [PATCH] Docs: Add note about event binding after build widget completes. See #1370 --- docs/example-widget-build-table.html | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/example-widget-build-table.html b/docs/example-widget-build-table.html index 288549af..ba26b8be 100644 --- a/docs/example-widget-build-table.html +++ b/docs/example-widget-build-table.html @@ -41,6 +41,7 @@

Notes

+

Adding event bindings

+
+

Internally, all triggered events use jQuery's triggerHandler method to get around the issue of events triggered on a nested table bubbling up to the parent table; e.g. we don't want a "sortEnd" event to trigger on a parent table when a nested table has completed sorting.

+ A binding added to the wrapper will not execute, and you can not target a table element that has not yet been created. +

To add an event listener to a table created by the build widget, you will need to use the initialized callback:

+ HTML (before) +
<!-- empty wrapper before the table has been built -->
+<div id="wrapper"></div>
+
+ Javascript +
$(function() {
+  $('#wrapper').tablesorter({
+    theme: 'blue',
+    widgets: ['zebra'],
+    data : dataObject,
+    initialized: function(table) {
+      $(table).on('sortStart', function() {
+        alert('ok');
+      });
+    }
+  });
+});
+ HTML (after) +
<div id="wrapper">
+  <table class="tablesorter-blue">
+    <!-- ... -->
+  </table>
+</div>
+
+

+
+

Options