Added fixedUrl option for use with the widget storage function. Fixes #389.

This commit is contained in:
Mottie 2013-10-18 11:40:39 -05:00
parent a33619a4fd
commit 340fdf0138
2 changed files with 22 additions and 4 deletions

View File

@ -707,6 +707,23 @@
<td><a href="example-option-sort-empty.html">Example</a></td>
</tr>
<tr id="fixedurl">
<td><a href="#" class="toggle2">fixedUrl</a></td>
<td>String</td>
<td>Undefined</td>
<td>
This option was added to set a specific page when storing data using the <code>$.tablesorter.storage</code> code. <span class="version">v2.12</span>.
<div class="collapsible"><br>
More specifically, when the storage function is used, it attempts to give every table a unique identifier using both the page <strong>url</strong> and table <strong>ID</strong> (or index on the page if no id exists). This option allows you to override the current page url (<em>it doesn't need to be a url, just some constant value</em>) and save data for multiple tables across a domain.<br>
<br>
The table url &amp; id can also be overridden by setting table data attributes <code>data-table-page</code> (url) and <code>data-table-group</code> (id)<br>(e.g. <code>&lt;table class=&quot;tablesorter&quot; data-table-page=&quot;mydomain&quot; data-table-group=&quot;financial&quot;&gt;...&lt;/table&gt;</code>)<br>
<br>
For a bit more detail, specifically on how to use the new storage function options for a custom widget, please refer to <a href="https://github.com/Mottie/tablesorter/issues/389#issuecomment-26594259">issue #389</a>.
</div>
</td>
<td></td>
</tr>
<tr id="headerlist">
<td><span class="permalink">headerList</span></td>
<td>Array</td>

View File

@ -1,4 +1,4 @@
/*! tableSorter 2.8+ widgets - updated 6/4/2013
/*! tableSorter 2.8+ widgets - updated 10/18/2013
*
* Column Styles
* Column Filters
@ -66,10 +66,11 @@ ts.themes = {
val = (v && v.hasOwnProperty('mywidget')) ? v.mywidget : '';
alert(val); // "data1" if saved, or "" if not
*/
ts.storage = function(table, key, val){
ts.storage = function(table, key, val, options){
var d, k, ls = false, v = {},
id = table.id || $('.tablesorter').index( $(table) ),
url = window.location.pathname;
c = table.config,
id = options && options.id || $(table).attr(options && options.group || 'data-table-group') || table.id || $('.tablesorter').index( $(table) ),
url = options && options.url || $(table).attr(options && options.page || 'data-table-page') || c && c.fixedUrl || window.location.pathname;
// https://gist.github.com/paulirish/5558557
if ("localStorage" in window) {
try {