Core: applyWidgetId properly accepts jQuery table element

This commit is contained in:
Rob Garrison 2016-02-15 12:02:54 -06:00
parent 5560f12011
commit e2d2b472c6
3 changed files with 9 additions and 8 deletions

View File

@ -177,12 +177,10 @@
// Exterminate, annhilate, destroy! http://www.youtube.com/watch?v=LOqn8FxuyFs // Exterminate, annhilate, destroy! http://www.youtube.com/watch?v=LOqn8FxuyFs
var $t = $(this); var $t = $(this);
if (/Destroy/.test( $t.text() )){ if (/Destroy/.test( $t.text() )){
$table[0].config.widgets = ['zebra'];
$table.trigger('destroyPager'); $table.trigger('destroyPager');
$t.text('Restore Pager'); $t.text('Restore Pager');
} else { } else {
$table[0].config.widgets = ['zebra', 'pager']; $('table').trigger('applyWidgetId', 'pager');
$table.trigger('applyWidgets');
$t.text('Destroy Pager'); $t.text('Destroy Pager');
} }
return false; return false;
@ -233,6 +231,7 @@
<em>NOTE!</em> <em>NOTE!</em>
</p> </p>
<ul> <ul>
<li>In <span class="version updated">v2.25.4</span>, updated example to use <code>applyWidgetId</code> to re-apply the pager widget after being destroyed.</li>
<li>In <span class="version updated">v2.24.0</span>, a page size select option with a value of "all" will display all rows - not recommended for ajax interactions!</li> <li>In <span class="version updated">v2.24.0</span>, a page size select option with a value of "all" will display all rows - not recommended for ajax interactions!</li>
<li>In <span class="version">v2.19.0</span>, added <code>pageAndSize</code> method which allows setting both the pager page &amp; size.</li> <li>In <span class="version">v2.19.0</span>, added <code>pageAndSize</code> method which allows setting both the pager page &amp; size.</li>
<li>In <span class="version">v2.17.6</span>, added <code>{startRow:input}</code> and <code>{page:input}</code> variables to the <code>output</code> option.<p></p></li> <li>In <span class="version">v2.17.6</span>, added <code>{startRow:input}</code> and <code>{page:input}</code> variables to the <code>output</code> option.<p></p></li>

View File

@ -5132,19 +5132,20 @@ $.tablesorter.updateCell( config, $cell, resort, callback );</pre>
<tr id="applywidgetid"> <tr id="applywidgetid">
<td><a href="#" class="permalink">applyWidgetId</a></td> <td><a href="#" class="permalink">applyWidgetId</a></td>
<td>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 (<span class="version updated">v2.25.0</span>). <td>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 (<span class="version updated">v2.25.4</span>).
<div class="collapsible"> <div class="collapsible">
<p>In <span class="version updated">v2.25.4</span>, the direct method will now correctly accept <code>$('table')</code>. Previously, only <code>$('table')[0]</code> would work.</p>
<p>In <span class="version updated">v2.25.0</span>, 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.</p> <p>In <span class="version updated">v2.25.0</span>, 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.</p>
<p>Only <em>one</em> widget can be applied at a time using this method.</p> <p>Only <em>one</em> widget can be applied at a time using this method.</p>
<h4>Direct method:</h4> <h4>Direct method:</h4>
<pre class="prettyprint lang-js">$.tablesorter.applyWidgetId( $( 'table' ), 'zebra' );</pre> <pre class="prettyprint lang-js">$.tablesorter.applyWidgetId( $('table'), 'zebra' );</pre>
<h4>Triggered event method:</h4> <h4>Triggered event method:</h4>
<pre class="prettyprint lang-js">$(function(){ <pre class="prettyprint lang-js">$(function(){
// initialize tablesorter without the widget // initialize tablesorter without the widget
$("table").tablesorter(); $('table').tablesorter();
// click a button to apply the zebra striping // click a button to apply the zebra striping
$("button").click(function(){ $('button').click(function(){
$('table').trigger('applyWidgetId', 'zebra'); $('table').trigger('applyWidgetId', 'zebra');
return false; return false;
}); });
@ -5367,7 +5368,7 @@ $('table').trigger( 'search', [['', '', '', '', 'orange']] ); // find orange in
<pre class="prettyprint lang-js">$(function(){ <pre class="prettyprint lang-js">$(function(){
$('table').trigger('destroyPager'); $('table').trigger('destroyPager');
});</pre> });</pre>
The only way to restore the pager is to re-initialize the pager addon The only way to restore the pager addon is to re-initialize the pager addon:
<br> <br>
<pre class="prettyprint lang-js">$(function(){ <pre class="prettyprint lang-js">$(function(){
$('table').tablesorterPager(pagerOptions); $('table').tablesorterPager(pagerOptions);

View File

@ -1902,6 +1902,7 @@
}, },
applyWidgetId : function( table, id, init ) { applyWidgetId : function( table, id, init ) {
table = $(table)[0];
var applied, time, name, var applied, time, name,
c = table.config, c = table.config,
wo = c.widgetOptions, wo = c.widgetOptions,