Skip to content

Commit

Permalink
sortReset, saveSort widget & pager fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Feb 1, 2012
1 parent 6d3b5b3 commit 3a84867
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 30 deletions.
10 changes: 10 additions & 0 deletions README.markdown
Expand Up @@ -34,6 +34,16 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs


View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt). View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt).


####Version 2.0.27 (2012-1-31)

* Added `sortReset` option
* Setting this option to `true`, allows you to click on the header a third time to clear the sort
* Clearing the sort DOES NOT return the table to it's initial unsorted state.
* Added `saveSort` widget
* This widget will save the last sort to local storage, and will fallback to cookies.
* The widget does use the `JSON.stringify` function which is [not fully supported](http://caniuse.com/#search=json) (IE7), so if you plan to support it and use this widget, please include this [JSON library](https://github.com/douglascrockford/JSON-js).
* Fixed pager page size not sticking. Fix for [issue #24](https://github.com/Mottie/tablesorter/issues/24).

####Version 2.0.26 (2012-1-30) ####Version 2.0.26 (2012-1-30)


* Widgets should no longer be applied twice when an initial sort direction is added. Fix for [issue #21](https://github.com/Mottie/tablesorter/issues/21). * Widgets should no longer be applied twice when an initial sort direction is added. Fix for [issue #21](https://github.com/Mottie/tablesorter/issues/21).
Expand Down
4 changes: 2 additions & 2 deletions addons/pager/jquery.tablesorter.pager.js
@@ -1,6 +1,6 @@
/* /*
* tablesorter pager plugin * tablesorter pager plugin
* updated 10/28/2011 * updated 1/31/2012
*/ */


(function($) { (function($) {
Expand Down Expand Up @@ -125,7 +125,7 @@
}, },


setPageSize = function(table, size, c) { setPageSize = function(table, size, c) {
c.size = size; c.size = c.lastSize = size;
c.totalPages = Math.ceil(c.totalRows / c.size); c.totalPages = Math.ceil(c.totalRows / c.size);
c.pagerPositionSet = false; c.pagerPositionSet = false;
moveToPage(table, c); moveToPage(table, c);
Expand Down
4 changes: 2 additions & 2 deletions addons/pager/jquery.tablesorter.pager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions changelog.txt
@@ -1,5 +1,16 @@
TableSorter Change Log TableSorter Change Log


Version 2.0.27 (2012-1-31)
============================

* Added `sortReset` option
* Setting this option to `true`, allows you to click on the header a third time to clear the sort
* Clearing the sort DOES NOT return the table to it's initial unsorted state.
* Added `saveSort` widget
* This widget will save the last sort to local storage, and will fallback to cookies.
* The widget does use the `JSON.stringify` function which is [not fully supported](http://caniuse.com/#search=json) (IE7), so if you plan to support it and use this widget, please include this [JSON library](https://github.com/douglascrockford/JSON-js).
* Fixed pager page size not sticking. Fix for [issue #24](https://github.com/Mottie/tablesorter/issues/24).

Version 2.0.26 (2012-1-30) Version 2.0.26 (2012-1-30)
============================ ============================


Expand Down
2 changes: 1 addition & 1 deletion docs/example-widget-resizable.html
Expand Up @@ -125,7 +125,7 @@ <h1>HTML</h1>


<div class="next-up"> <div class="next-up">
<hr /> <hr />
Next up: <a href="example-widget-sticky-header.html">Applying the sticky header widget &rsaquo;&rsaquo;</a> Next up: <a href="example-widget-savesort.html">Applying the save sort widget &rsaquo;&rsaquo;</a>
</div> </div>


</div> </div>
Expand Down
130 changes: 130 additions & 0 deletions docs/example-widget-savesort.html
@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery plugin: Tablesorter 2.0 - Save Sort Widget</title>

<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>

<!-- Demo stuff -->
<link rel="stylesheet" href="css/jq.css">
<script src="js/chili/jquery.chili-2.2.js"></script>
<script src="js/chili/recipes.js"></script>
<script src="js/docs.js"></script>

<!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/blue/style.css">
<script src="../js/jquery.tablesorter.js"></script>
<script src="../js/jquery.tablesorter.widgets.js"></script>

<script id="js">$(function() {

// call the tablesorter plugin
$("table").tablesorter({

// use save sort widget
widgets: ["saveSort"]

});

});</script>
</head>
<body>
<div id="banner">
<h1>table<em>sorter</em></h1>
<h2>Save Sort Widget</h2>
<h3>Flexible client-side table sorting</h3>
<a href="index.html">Back to documentation</a>
</div>
<div id="main">

<p class="tip">
<em>NOTE!</em>
<ul>
<li>This widget can be applied to the original plugin. The code is in the "jquery.tablesorter.widgets.js" file.</li>
<li>Sort one or more columns, then reload the page to see that this widget remembers the last table sort.</li>
</ul>
</p>

<h1>Demo</h1>
<div id="demo"><table class="tablesorter">
<thead>
<tr>
<th>Account #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Total</th>
<th>Discount</th>
<th>Diff</th>
</tr>
</thead>
<tbody>
<tr>
<td>A43</td>
<td>Peter</td>
<td>Parker</td>
<td>28</td>
<td>9.99</td>
<td>20.3%</td>
<td>+3</td>
</tr>
<tr>
<td>A255</td>
<td>John</td>
<td>Hood</td>
<td>33</td>
<td>19.99</td>
<td>25.1%</td>
<td>-7</td>
</tr>
<tr>
<td>A33</td>
<td>Clark</td>
<td>Kent</td>
<td>18</td>
<td>15.89</td>
<td>44.2%</td>
<td>-15</td>
</tr>
<tr>
<td>A1</td>
<td>Bruce</td>
<td>Almighty</td>
<td>45</td>
<td>153.19</td>
<td>44%</td>
<td>+19</td>
</tr>
<tr>
<td>A102</td>
<td>Bruce</td>
<td>Evans</td>
<td>56</td>
<td>153.19</td>
<td>23%</td>
<td>+9</td>
</tr>
</tbody>
</table></div>

<h1>Javascript</h1>
<div id="javascript">
<pre class="js"></pre>
</div>
<h1>HTML</h1>
<div id="html">
<pre class="html"></pre>
</div>

<div class="next-up">
<hr />
Next up: <a href="example-widget-sticky-header.html">Applying the sticky header widget &rsaquo;&rsaquo;</a>
</div>

</div>

</body>
</html>

31 changes: 21 additions & 10 deletions docs/index.html
Expand Up @@ -89,8 +89,8 @@ <h1>Contents</h1>
<li><a href="#Getting-Started">Getting started</a></li> <li><a href="#Getting-Started">Getting started</a></li>
<li><a href="#Examples">Examples</a></li> <li><a href="#Examples">Examples</a></li>
<li><a href="#Configuration">Configuration</a></li> <li><a href="#Configuration">Configuration</a></li>
<li><a href="#Methods">Methods</a> <span class="tip"><em>New!</em></span></li> <li><a href="#Methods">Methods</a></li>
<li><a href="#Events">Events</a> <span class="tip"><em>New!</em></span></li> <li><a href="#Events">Events</a></li>
<li><a href="#Download">Download</a></li> <li><a href="#Download">Download</a></li>
<li><a href="#Compatibility">Compatibility</a></li> <li><a href="#Compatibility">Compatibility</a></li>
<li><a href="#Support">Support</a></li> <li><a href="#Support">Support</a></li>
Expand Down Expand Up @@ -307,8 +307,8 @@ <h4>Sorting</h4>
<h4>Parsers / Extracting Content</h4> <h4>Parsers / Extracting Content</h4>
<ul> <ul>
<li><a href="example-option-digits.html">Dealing with digits!</a></li> <li><a href="example-option-digits.html">Dealing with digits!</a></li>
<li><a href="example-options-headers-digits-strings.html">Dealing with text strings in numerical sorts</a> <span class="tip"><em>New! v2.0.10</em></span></li> <li><a href="example-options-headers-digits-strings.html">Dealing with text strings in numerical sorts</a> (v2.0.10)</li>
<li><a href="example-parsers-class-name.html">Disable or set the column parser using class names</a> <span class="tip"><em>New! v2.0.11</em></span></li> <li><a href="example-parsers-class-name.html">Disable or set the column parser using class names</a> (v2.0.11)</li>
<li><a href="example-option-date-format.html">Changing the date format</a> <span class="tip"><em>New! v2.0.23</em></span></li> <li><a href="example-option-date-format.html">Changing the date format</a> <span class="tip"><em>New! v2.0.23</em></span></li>
<li><a href="example-parsers.html">Parser, writing your own</a></li> <li><a href="example-parsers.html">Parser, writing your own</a></li>
<li><a href="example-option-text-extraction.html">Dealing with markup inside cells (textExtraction function)</a></li> <li><a href="example-option-text-extraction.html">Dealing with markup inside cells (textExtraction function)</a></li>
Expand All @@ -317,11 +317,12 @@ <h4>Parsers / Extracting Content</h4>
<h4>Widgets / Plugins</h4> <h4>Widgets / Plugins</h4>
<ul> <ul>
<li><a href="example-apply-widget.html">Applying widgets</a></li> <li><a href="example-apply-widget.html">Applying widgets</a></li>
<li><a href="example-widget-columns.html">Columns widget</a> <span class="tip"><em>New! v2.0.17</em></span></li> <li><a href="example-widget-columns.html">Columns widget</a> (v2.0.17)</li>
<li><a href="example-widget-filter.html">Filter widget</a> <span class="tip"><em>New! v2.0.18</em></span></li> <li><a href="example-widget-filter.html">Filter widget</a> (v2.0.18)</li>
<li><a href="example-widget-ui-theme.html">jQuery UI theme widget</a> <span class="tip"><em>New! v2.0.9</em></span></li> <li><a href="example-widget-ui-theme.html">jQuery UI theme widget</a> (v2.0.9)</li>
<li><a href="example-widget-resizable.html">Resizable Columns widget</a> <span class="tip"><em>New! v2.0.23.1</em></span></li> <li><a href="example-widget-resizable.html">Resizable Columns widget</a> <span class="tip"><em>New! v2.0.23.1</em></span></li>
<li><a href="example-widget-sticky-header.html">Sticky header widget</a> <span class="tip"><em>New! v2.0.21.1</em></span></li> <li><a href="example-widget-savesort.html">Save sort widget</a> <span class="tip"><em>New! v2.0.27</em></span></li>
<li><a href="example-widget-sticky-header.html">Sticky header widget</a> (v2.0.21.1)</li>
<li><a href="example-widget-zebra.html">Zebra stripe widget</a></li> <li><a href="example-widget-zebra.html">Zebra stripe widget</a></li>
<li><a href="example-widgets.html">Widgets, writing your own</a></li> <li><a href="example-widgets.html">Widgets, writing your own</a></li>
<li><a href="example-pager.html">Pager plugin</a></li> <li><a href="example-pager.html">Pager plugin</a></li>
Expand All @@ -334,14 +335,14 @@ <h4>Adding / Removing Content</h4>
<ul> <ul>
<li><a href="example-empty-table.html">Initializing tablesorter on a empty table</a></li> <li><a href="example-empty-table.html">Initializing tablesorter on a empty table</a></li>
<li><a href="example-ajax.html">Appending table data with ajax</a></li> <li><a href="example-ajax.html">Appending table data with ajax</a></li>
<li><a href="example-add-rows.html">Adding a table row</a> <span class="tip"><em>New! v2.0.16</em></span></li> <li><a href="example-add-rows.html">Adding a table row</a> (v2.0.16)</li>
<li><a href="example-update-cell.html">Update the table after cell content has changed</a></li> <li><a href="example-update-cell.html">Update the table after cell content has changed</a></li>
<li><a href="example-pager.html">Pager plugin</a> - examples of how to add and remove rows</li> <li><a href="example-pager.html">Pager plugin</a> - examples of how to add and remove rows</li>
</ul> </ul>


<h4>Change Header Style</h4> <h4>Change Header Style</h4>
<ul> <ul>
<li><a href="example-widget-ui-theme.html">jQuery UI theme widget</a> <span class="tip"><em>New! v2.0.9</em></span></li> <li><a href="example-widget-ui-theme.html">jQuery UI theme widget</a> (v2.0.9)</li>
<li><a href="example-option-render-header.html">Modify how the header is rendered to allow for custom styling</a></li> <li><a href="example-option-render-header.html">Modify how the header is rendered to allow for custom styling</a></li>
</ul> </ul>


Expand Down Expand Up @@ -740,6 +741,16 @@ <h1>Configuration</h1>
<td></td> <td></td>
</tr> </tr>


<tr id="sortreset">
<td>sortReset</td>
<td>Boolean</td>
<td>false</td>
<td>
Setting this option to <code class="hilight">true</code> will allow you to click on the table header a third time to reset the sort direction. However, it does not restore the original sort order, it merely clear the sort from the header. <span class="tip"><em>New!</em></span> in v2.0.27.
</td>
<td></td>
</tr>

<tr id="sortmultisortkey"> <tr id="sortmultisortkey">
<td>sortMultiSortKey</td> <td>sortMultiSortKey</td>
<td>String</td> <td>String</td>
Expand Down
15 changes: 10 additions & 5 deletions js/jquery.tablesorter.js
@@ -1,6 +1,6 @@
/* /*
* TableSorter 2.0 - Client-side table sorting with ease! * TableSorter 2.0 - Client-side table sorting with ease!
* Version 2.0.26 * Version 2.0.27
* @requires jQuery v1.2.3 * @requires jQuery v1.2.3
* *
* Copyright (c) 2007 Christian Bach * Copyright (c) 2007 Christian Bach
Expand Down Expand Up @@ -462,6 +462,7 @@
}); });
l = list.length; l = list.length;
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
if (list[i][1] === 2) { continue; } // direction = 2 means reset!
h[list[i][0]].addClass(css[list[i][1]]); h[list[i][0]].addClass(css[list[i][1]]);
} }
} }
Expand Down Expand Up @@ -639,7 +640,7 @@
// get current column index // get current column index
i = this.column; i = this.column;
// get current column sort order // get current column sort order
this.order = this.count++ % 2; this.order = this.count++ % (config.sortReset ? 3 : 2);
// always sort on the locked order. // always sort on the locked order.
if(typeof(this.lockedOrder) !== "undefined" && this.lockedOrder !== false) { this.order = this.lockedOrder; } if(typeof(this.lockedOrder) !== "undefined" && this.lockedOrder !== false) { this.order = this.lockedOrder; }
// user only wants to sort on one column // user only wants to sort on one column
Expand All @@ -655,7 +656,7 @@
} }
} }
// add column to sort list // add column to sort list
config.sortList.push([i, this.order]); if (this.order < 2) { config.sortList.push([i, this.order]); }
// multi column sorting // multi column sorting
} else { } else {
// the user has clicked on an already sorted column. // the user has clicked on an already sorted column.
Expand All @@ -667,12 +668,16 @@
if (s[0] === i) { if (s[0] === i) {
o.count = s[1]; o.count = s[1];
o.count++; o.count++;
s[1] = o.count % 2; s[1] = o.count % (config.sortReset ? 3 : 2);
if (s[1] >= 2) {
config.sortList.splice(j,1);
o.count = 0;
}
} }
} }
} else { } else {
// add column to sort list array // add column to sort list array
config.sortList.push([i, this.order]); if (this.order < 2) { config.sortList.push([i, this.order]); }
} }
} }
if (config.sortAppend !== null) { if (config.sortAppend !== null) {
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.tablesorter.min.js

Large diffs are not rendered by default.

0 comments on commit 3a84867

Please sign in to comment.