mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Docs: Add note about event binding after build widget completes. See #1370
This commit is contained in:
parent
c91ceeb5b1
commit
c4eb30992a
@ -41,6 +41,7 @@
|
||||
<h3><a href="#">Notes</a></h3>
|
||||
<div>
|
||||
<ul>
|
||||
<li>To bind events to the newly created table, see the <strong>Adding event bindings</strong> section below.</li>
|
||||
<li>Build a table starting with an assortment of data types ( array, text (CSV, HTML) or object (json) ).</li>
|
||||
<li>This widget isn't really a widget because it is run and does it's processing before tablesorter has initialized; but the options for it are contained within the tablesorter <code>widgetOptions</code>.</li>
|
||||
<li>Using the core build options:
|
||||
@ -65,6 +66,38 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h3><a href="#">Adding event bindings</a></h3>
|
||||
<div>
|
||||
<p>Internally, all triggered events use jQuery's <a href="http://api.jquery.com/triggerHandler/">triggerHandler</a> 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.</p>
|
||||
<strong>A binding added to the wrapper will not execute, and you can not target a table element that has not yet been created.</strong>
|
||||
<p>To add an event listener to a table created by the build widget, you will need to use the <code>initialized</code> callback:</p>
|
||||
HTML (before)
|
||||
<pre class="prettyprint lang-html"><!-- empty wrapper before the table has been built -->
|
||||
<div id="wrapper"></div>
|
||||
</pre>
|
||||
Javascript
|
||||
<pre class="prettyprint lang-js">$(function() {
|
||||
$('#wrapper').tablesorter({
|
||||
theme: 'blue',
|
||||
widgets: ['zebra'],
|
||||
data : dataObject,
|
||||
initialized: function(table) {
|
||||
$(table).on('sortStart', function() {
|
||||
alert('ok');
|
||||
});
|
||||
}
|
||||
});
|
||||
});</pre>
|
||||
HTML (after)
|
||||
<pre class="prettyprint lang-html"><div id="wrapper">
|
||||
<table class="tablesorter-blue">
|
||||
<!-- ... -->
|
||||
</table>
|
||||
</div>
|
||||
</pre>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h3><a href="#">Options</a></h3>
|
||||
<div>
|
||||
<table class="tablesorter-blue">
|
||||
|
Loading…
Reference in New Issue
Block a user