Add resetToLoadState method

This commit is contained in:
Mottie 2014-05-16 13:22:58 -05:00
parent a6b87c7882
commit 42f363c96f
2 changed files with 22 additions and 0 deletions

View File

@ -3576,6 +3576,18 @@ This ajaxProcessing function must return an object with "total", "headers" and "
<td><a href="example-add-rows.html">Example</a></td> <td><a href="example-add-rows.html">Example</a></td>
</tr> </tr>
<tr id="resettoloadstate">
<td><a href="#" class="permalink">resetToLoadState</a></td>
<td>Use this method reset the table to it's original settings. (<span class="version">v2.16.5</span>).
<div class="collapsible">
Using this method will clear out any settings that have changed since the table was initialized (refreshes the entire table); so any sorting or modified widget options will be cleared.<br>
However, it will not clear any values that were saved to storage. This method is basically like reloading the page.
<pre class="prettyprint lang-js">$('table').trigger('resetToLoadState');</pre>
</div>
</td>
<td></td>
</tr>
<tr id="sort"> <tr id="sort">
<td><a href="#" class="permalink">sort</a></td> <td><a href="#" class="permalink">sort</a></td>
<td>Use this method to initialize a sort while targeting a specific column header (<span class="version">v2.9</span>). <td>Use this method to initialize a sort while targeting a specific column header (<span class="version">v2.9</span>).

View File

@ -948,6 +948,14 @@
.bind("destroy" + c.namespace, function(e, c, cb){ .bind("destroy" + c.namespace, function(e, c, cb){
e.stopPropagation(); e.stopPropagation();
ts.destroy(table, c, cb); ts.destroy(table, c, cb);
})
.bind("resetToLoadState" + c.namespace, function(e){
// restore original settings; this clears out current settings, but does not clear
// values saved to storage.
c = $.extend(true, ts.defaults, c.originalSettings);
table.hasInitialized = false;
// setup the entire table again
ts.setup( table, c );
}); });
} }
@ -957,6 +965,8 @@
var table = this, var table = this,
// merge & extend config options // merge & extend config options
c = $.extend(true, {}, ts.defaults, settings); c = $.extend(true, {}, ts.defaults, settings);
// save initial settings
c.originalSettings = settings;
// create a table from data (build table widget) // create a table from data (build table widget)
if (!table.hasInitialized && ts.buildTable && this.tagName !== 'TABLE') { if (!table.hasInitialized && ts.buildTable && this.tagName !== 'TABLE') {
// return the table (in case the original target is the table's container) // return the table (in case the original target is the table's container)