added emptyTo and stringTo options

This commit is contained in:
Rob Garrison 2012-04-20 11:09:43 -05:00
parent a5607ae960
commit ee173ba65a
7 changed files with 221 additions and 115 deletions

View File

@ -35,9 +35,37 @@ tablesorter can successfully parse and sort many types of data including linked
View the [complete listing here](https://github.com/Mottie/tablesorter/wiki/Change). View the [complete listing here](https://github.com/Mottie/tablesorter/wiki/Change).
#### Version 2.1.16 (4/20/2012)
* Removed `emptyToBottom` option. It has been replaced with the `emptyTo` option.
* Added `emptyTo` option:
* Setting it to `top` will always sort all empty table cells to the top of the table.
* `bottom` will always sort all empty cells to the bottom of the table.
* `none` or `zero` will treat empty cells as if their value was zero.
* Individual columns can be modified by adding the following, set in order of priority:
* metadata `class="{ empty: 'top' }"`. This requires the metadata plugin.
* headers option `headers : { 0 : { empty : 'top' } }`.
* header class name `class="empty-top"`.
* Overall `emptyTo` option.
* Updated the [sorting empty cells](http://mottie.github.com/tablesorter/docs/example-option-sort-empty.html) demo.
* Add `stringTo` option in version 2.1.16. This options sets the string value for all of the numerical columns.
* Modified the `string` option which is only applied to text within a numerical column; setting the value to:
* `max` will treat any text in that column as a value greater than the max (more positive) value. Same as the `max+` value, which was retained for backwards compatibility.
* `min` will treat any text in that column as a value greater than the min (more negative) value. Same as the `max-` value.
* `top` will always sort the text to the top of the column.
* `bottom` will always sort the text to the bottom of the column.
* `none` or `zero` will treat the text as if it has a value of zero.
* Individual columns can be modified by adding the following, set in order of priority:
* metadata `class="{ string: 'top' }"`. This requires the metadata plugin.
* headers option `headers : { 0 : { string : 'top' } }`.
* header class name `class="string-top"`.
* Overall `stringTo` option.
* Updated the [text strings in numerical sort](http://mottie.github.com/tablesorter/docs/example-options-headers-digits-strings.html).
#### Version 2.1.15 (4/18/2012) #### Version 2.1.15 (4/18/2012)
* Modified the `emptyAtBottom` option: * Modified the `emptyToBottom` option:
* Clarified that setting this option to `null` will treat empty cells as if they had a value of zero. Fix for [issue #48](https://github.com/Mottie/tablesorter/issues/48). * Clarified that setting this option to `null` will treat empty cells as if they had a value of zero. Fix for [issue #48](https://github.com/Mottie/tablesorter/issues/48).
* Modified the script so that empty cells do not call their respective parser to keep the `emptyAtBottom` functionality working properly. Fix for [issue #49](https://github.com/Mottie/tablesorter/issues/49). * Modified the script so that empty cells do not call their respective parser to keep the `emptyAtBottom` functionality working properly. Fix for [issue #49](https://github.com/Mottie/tablesorter/issues/49).

View File

@ -20,7 +20,8 @@
<script id="js">$(function() { <script id="js">$(function() {
// call the tablesorter plugin // call the tablesorter plugin
$("table").tablesorter({ $("table").tablesorter({
emptyToBottom: true // default "emptyTo"
emptyTo: 'bottom'
}); });
});</script> });</script>
@ -28,10 +29,9 @@
$(function(){ $(function(){
$('select').change(function(){ $('select').change(function(){
var t = $('table'), var t = $('table'),
etb = $(this).val(), v = $(this).val();
v = (etb === 'true') ? true : (etb === 'false' ? false : null); t[0].config.emptyTo = v;
t[0].config.emptyToBottom = v; t.trigger("update");
t.trigger("sorton", [t[0].config.sortList]);
}); });
}); });
</script> </script>
@ -47,26 +47,35 @@ $(function(){
<p class="tip"> <p class="tip">
<em>NOTE!</em> <em>NOTE!</em>
Set the <code class="hilight">emptyToBottom</code> selector below: Set the <code class="hilight">emptyTo</code> selector below:
<ul> <ul>
<li>true - sort empty table cells to the bottom.</li> <li><code class="hilight">top</code> - sort empty table cells to the top.</li>
<li>false - sort empty table cells to the top.</li> <li><code class="hilight">bottom</code> - sort empty table cells to the bottom.</li>
<li>null - sort empty table cells as if the cell has the value equal to zero.</li> <li><code class="hilight">none</code> or <code class="hilight">zero</code> - sort empty table cells as if the cell has the value equal to zero.</li>
<li>Individual columns can be modified by adding the following, set in order of priority:
<ul>
<li>metadata <code class="hilight">class="{ empty: 'top'}"</code>. This requires the metadata plugin.</li>
<li>headers option <code class="hilight">headers : { 0 : { empty : 'top' } }</code>.</li>
<li>header class name <code class="hilight">class="empty-top"</code>.</li>
<li>Overall <code>emptyTo</code> option.</li>
</ul>
</li>
<li><code class="hilight">emptyToBottom</code> option was added in v2.1.11, then replaced by the <code class="hilight">emptyTo</code> option in v2.1.16.</li>
</ul> </ul>
</p> </p>
<h1>Demo</h1> <h1>Demo</h1>
Set <code class="hilight">emptyToBottom</code> option: <select> Set <code class="hilight">emptyTo</code> option: <select>
<option>true</option> <option>bottom</option>
<option>false</option> <option>top</option>
<option>null</option> <option>zero</option>
</select> </select>
<div id="demo"><table class="tablesorter"> <div id="demo"><table class="tablesorter">
<thead> <thead>
<tr> <tr>
<th>Account #</th> <th class="empty-top">Account #</th> <!-- empty-top class has higher priority than the "emptyTo" option -->
<th>First Name</th> <th>First Name</th>
<th>Last Name</th> <th>Last Name</th>
<th>Age</th> <th>Age</th>
@ -150,6 +159,7 @@ Set <code class="hilight">emptyToBottom</code> option: <select>
</tr> </tr>
</tbody> </tbody>
</table></div> </table></div>
* Note: The "Account #" column has the "empty-top" class name set which over-rides the <code class="hilight">emptyTo</code> option.
<h1>Javascript</h1> <h1>Javascript</h1>
<div id="javascript"> <div id="javascript">

View File

@ -23,13 +23,16 @@
<script id="js">$(function() { <script id="js">$(function() {
// call the tablesorter plugin // call the tablesorter plugin
$("table").tablesorter({ $("table").tablesorter({
// default strings setting
stringTo: "max",
// columns 2 & 3 (zero-based index) set using headers option
// columns 4+ set using header class name: "string-max", "string-min", "string-top", "string-bottom" and "string-none"
headers: { headers: {
5: { sorter: "digit", string: "max+" }, // non-numeric content is treated as a MAX value 1: { sorter: "digit", empty : "top" }, // sort empty cells to the top
6: { sorter: "digit", string: "max-" }, // non-numeric content is treated as a MIN value 2: { sorter: "digit", string: "max" }, // non-numeric content is treated as a MAX value
7: { sorter: "digit", string: "max+" }, // non-numeric content is treated as a MAX value 3: { sorter: "digit", string: "min" } // non-numeric content is treated as a MIN value
8: { sorter: "digit", string: "max-" }, // non-numeric content is treated as a MIN value
9: { sorter: "digit" } // non-numeric content is given a value of ZERO (default)
} }
}); });
});</script> });</script>
</head> </head>
@ -46,10 +49,27 @@
<em>NOTE!</em> <em>NOTE!</em>
<ul> <ul>
<li>This functionality is new as of version 2.0.10 (not part of the original plugin).</li> <li>This functionality is new as of version 2.0.10 (not part of the original plugin).</li>
<li>When a column is sorted numerically ( sorter:"digit" ) any text in that column will, by default, be given a <em>zero</em> value. Sort the last column (#9) to see the problem with this method.</li> <li>When a column is sorted numerically ( <code class="hilight">sorter:"digit"</code> ) any text in that column will, by default, be given a <em>zero</em> value. Sort the last column (#9) to see the problem with this method.</li>
<li>Set the headers option "string" value to "max+" to treat any text in that column as a value greater than the <em>max positive</em> value.</li> <li>Overall <code class="hilight">stringTo</code> option added in version 2.1.16.</li>
<li>Set the headers option "string" value to "max-" to treat any text in that column as a value greater than the <em>max negative</em> value.</li> <li>String options changed in version 2.1.16; setting the value to:
<li>Sort columns five through eight to see how the sort has changed. Note that the text is sorted separately from the numeric values.</li> <ul>
<li><code class="hilight">"max"</code> will treat any text in that column as a value greater than the <em>max</em> (more positive) value. Renamed from "max+".</li>
<li><code class="hilight">"min"</code> will treat any text in that column as a value greater than the <em>min</em> (more negative) value. Renamed from "max-".</li>
<li><code class="hilight">"top"</code> will always sort the text to the top of the column.</li>
<li><code class="hilight">"bottom"</code> will always sort the text to the bottom of the column.</li>
<li><code class="hilight">"none"</code> or <code class="hilight">"zero"</code> will treat the text as if it has a value of zero.</li>
</ul>
</li>
<li>Individual columns can be modified by adding the following, set in order of priority:
<ul>
<li>metadata <code class="hilight">class="{ string: 'top'}"</code>. This requires the metadata plugin.</li>
<li>headers option <code class="hilight">headers : { 0 : { string : 'top' } }</code>.</li>
<li>header class name <code class="hilight">class="string-top"</code>.</li>
<li>Overall <code class="hilight">stringTo</code> option.</li>
</ul>
</li>
<li>Sort columns three through eight to see how the sort has changed. Note that the text is sorted separately from the numeric values.</li>
<li>The <code class="hilight">emptyTo</code> option defaults to bottom, so all empty cells will sort at the bottom of the table, except fo the second column.</li>
</ul> </ul>
</p> </p>
@ -58,137 +78,126 @@
<thead> <thead>
<tr> <tr>
<th>Account #</th> <th>Account #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Difference</th> <th>Difference</th>
<th>5: Ratings (max+)</th> <th>3: Ratings (max)</th>
<th>6: Ratings (max-)</th> <th>4: Ratings (min)</th>
<th>7: Change (max+)</th> <th class="string-max">5: Change (max)</th>
<th>8: Change (max-)</th> <th class="string-min">6: Change (min)</th>
<th>9: Change (none)</th> <th class="string-top">7: Change (top)</th>
<th class="string-bottom">8: Change (bottom)</th>
<th class="string-none">9: Change (zero)</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>A43</td> <td>A43</td>
<td>Peter</td>
<td>Parker</td>
<td>28</td>
<td>-35</td> <td>-35</td>
<td>01</td> <td>01</td>
<td>01</td> <td>01</td>
<td>-.1</td> <td>-.1</td>
<td>-.1</td> <td>-.1</td>
<td>-.1</td> <td>-.1</td>
<td>-.1</td>
<td>-.1</td>
</tr> </tr>
<tr> <tr>
<td>A255</td> <td>A255</td>
<td>John</td>
<td>Hood</td>
<td>33</td>
<td>33</td> <td>33</td>
<td>02</td> <td>02</td>
<td>02</td> <td>02</td>
<td>N/A #1</td> <td>N/A #1</td>
<td>N/A #1</td> <td>N/A #1</td>
<td>N/A #1</td> <td>N/A #1</td>
<td>N/A #1</td>
<td>N/A #1</td>
</tr> </tr>
<tr> <tr>
<td>A33</td> <td>A33</td>
<td>Clark</td>
<td>Kent</td>
<td>18</td>
<td>2</td> <td>2</td>
<td>03</td> <td>03</td>
<td>03</td> <td>03</td>
<td>N/A #2</td> <td>N/A #2</td>
<td>N/A #2</td> <td>N/A #2</td>
<td>N/A #2</td> <td>N/A #2</td>
<td>N/A #2</td>
<td>N/A #2</td>
</tr> </tr>
<tr> <tr>
<td>A1</td> <td>A1</td>
<td>Bruce</td>
<td>Almighty</td>
<td>45</td>
<td>-5</td> <td>-5</td>
<td>04</td> <td>04</td>
<td>04</td> <td>04</td>
<td>-8.4</td> <td>-8.4</td>
<td>-8.4</td> <td>-8.4</td>
<td>-8.4</td> <td>-8.4</td>
<td>-8.4</td>
<td>-8.4</td>
</tr> </tr>
<tr> <tr>
<td>A102</td> <td>A102</td>
<td>Bruce</td>
<td>Evans</td>
<td>22</td>
<td>99</td> <td>99</td>
<td>05</td> <td>05</td>
<td>05</td> <td>05</td>
<td>-2.2</td> <td>-2.2</td>
<td>-2.2</td> <td>-2.2</td>
<td>-2.2</td> <td>-2.2</td>
<td>-2.2</td>
<td>-2.2</td>
</tr> </tr>
<tr> <tr>
<td>A10</td> <td>A10</td>
<td>James</td>
<td>Sullivan</td>
<td>46</td>
<td>-1</td> <td>-1</td>
<td>06</td> <td>06</td>
<td>06</td> <td>06</td>
<td>97.4</td> <td>97.4</td>
<td>97.4</td> <td>97.4</td>
<td>97.4</td> <td>97.4</td>
<td>97.4</td>
<td>97.4</td>
</tr> </tr>
<tr> <tr>
<td>A02</td> <td>A02</td>
<td>Bruce</td>
<td>Campbell</td>
<td>32</td>
<td>0</td> <td>0</td>
<td>07</td> <td>07</td>
<td>07</td> <td>07</td>
<td>23.6</td> <td>23.6</td>
<td>23.6</td> <td>23.6</td>
<td>23.6</td> <td>23.6</td>
<td>23.6</td>
<td>23.6</td>
</tr> </tr>
<tr> <tr>
<td>A55</td> <td>A55</td>
<td>Frank</td>
<td>Evans</td>
<td>51</td>
<td>44</td> <td>44</td>
<td></td> <td></td>
<td></td> <td></td>
<td>11.4</td> <td>11.4</td>
<td>11.4</td> <td>11.4</td>
<td>11.4</td> <td>11.4</td>
<td>11.4</td>
<td>11.4</td>
</tr> </tr>
<tr> <tr>
<td>A87</td> <td>A87</td>
<td>Joe</td>
<td>Smith</td>
<td>24</td>
<td>04</td> <td>04</td>
<td>NR</td> <td>NR</td>
<td>NR</td> <td>NR</td>
<td>5.2</td> <td>5.2</td>
<td>5.2</td> <td>5.2</td>
<td>5.2</td> <td>5.2</td>
<td>5.2</td>
<td>5.2</td>
</tr> </tr>
<tr> <tr>
<td>A012</td> <td>A012</td>
<td>Mike</td> <td></td>
<td>Wazowski</td>
<td>21</td>
<td>-24</td>
<td>NR</td> <td>NR</td>
<td>NR</td> <td>NR</td>
<td></td> <td></td>
<td></td> <td></td>
<td></td> <td></td>
<td></td>
<td></td>
</tr> </tr>
</tbody> </tbody>
</table></div> </table></div>

View File

@ -562,18 +562,26 @@
<td><a href="example-option-debug.html">Example</a></td> <td><a href="example-option-debug.html">Example</a></td>
</tr> </tr>
<tr id="emptytobottom"> <tr id="emptyto">
<td><a href="#" class="toggle2">emptyToBottom</a></td> <td><a href="#" class="toggle2">emptyTo</a></td>
<td>Boolean</td> <td>String</td>
<td>true</td> <td>"bottom"</td>
<td> <td>
Boolean flag indicating how tablesorter should deal with empty table cells. <span class="tip"><em>New!</em></span> v2.1.11 Boolean flag indicating how tablesorter should deal with empty table cells. <span class="tip"><em>Modified!</em></span> v2.1.16.
<div class="collapsible"> <div class="collapsible">
<ul> <ul>
<li><code class="hilight">true</code> - sort empty table cells to the bottom.</li> <li><code class="hilight">bottom</code> - sort empty table cells to the bottom.</li>
<li><code class="hilight">false</code> - sort empty table cells to the top.</li> <li><code class="hilight">top</code> - sort empty table cells to the top.</li>
<li><code class="hilight">null</code> - sort empty table cells as if the cell has the lowest value (less than "a" and "0").</li> <li><code class="hilight">none</code> or <code class="hilight">zero</code> - sort empty table cells as if the cell has the value equal to zero.</li>
</ul> </ul>
Individual columns can be modified by adding the following, set in order of priority:
<ul>
<li>metadata <code class="hilight">class="{ empty: 'top'}"</code>. This requires the metadata plugin.</li>
<li>headers option <code class="hilight">headers : { 0 : { empty : 'top' } }</code>.</li>
<li>header class name <code class="hilight">class="empty-top"</code>.</li>
<li>Overall <code>emptyTo</code> option.</li>
</ul>
<code class="hilight">emptyToBottom</code> option was added in v2.1.11, then replaced by the <code class="hilight">emptyTo</code> option in v2.1.16.
</div> </div>
</td> </td>
<td><a href="example-option-sort-empty.html">Example</a></td> <td><a href="example-option-sort-empty.html">Example</a></td>
@ -808,6 +816,33 @@
<td><a href="example-option-sort-key.html">Example</a></td> <td><a href="example-option-sort-key.html">Example</a></td>
</tr> </tr>
<tr id="stringto">
<td><a href="#" class="toggle2">stringTo</a></td>
<td>String</td>
<td>"max"</td>
<td>
Boolean flag indicating how tablesorter should deal with text inside of numerically sorted columns. <span class="tip"><em>New!</em></span> v2.1.16.
<div class="collapsible"><br>
String options was initially set in the header options only. Overall option added and values changed in version 2.1.16; setting the value to:
<ul>
<li><code class="hilight">"max"</code> will treat any text in that column as a value greater than the <em>max</em> (more positive) value. Renamed from "max+".</li>
<li><code class="hilight">"min"</code> will treat any text in that column as a value greater than the <em>min</em> (more negative) value. Renamed from "max-".</li>
<li><code class="hilight">"top"</code> will always sort the text to the top of the column.</li>
<li><code class="hilight">"bottom"</code> will always sort the text to the bottom of the column.</li>
<li><code class="hilight">"none"</code> or <code class="hilight">"zero"</code> will treat the text as if it has a value of zero.</li>
</ul>
Individual columns can be modified by adding the following, set in order of priority:
<ul>
<li>metadata <code class="hilight">class="{ string: 'top'}"</code>. This requires the metadata plugin.</li>
<li>headers option <code class="hilight">headers : { 0 : { string : 'top' } }</code>.</li>
<li>header class name <code class="hilight">class="string-top"</code>.</li>
<li>Overall <code class="hilight">stringTo</code> option.</li>
</ul>
</div>
</td>
<td><a href="example-options-headers-digits-strings.html">Example</a></td>
</tr>
<tr id="tableClass"> <tr id="tableClass">
<td>tableClass</td> <td>tableClass</td>
<td>String</td> <td>String</td>

View File

@ -1,5 +1,5 @@
/*! /*!
* TableSorter 2.1.15 - Client-side table sorting with ease! * TableSorter 2.1.16 - Client-side table sorting with ease!
* @requires jQuery v1.2.6+ * @requires jQuery v1.2.6+
* *
* Copyright (c) 2007 Christian Bach * Copyright (c) 2007 Christian Bach
@ -18,7 +18,7 @@
$.extend({ $.extend({
tablesorter: new function(){ tablesorter: new function(){
this.version = "2.1.15"; this.version = "2.1.16";
var parsers = [], widgets = [], tbl; var parsers = [], widgets = [], tbl;
this.defaults = { this.defaults = {
@ -33,11 +33,14 @@
sortLocaleCompare: false, sortLocaleCompare: false,
sortReset: false, sortReset: false,
sortRestart: false, sortRestart: false,
emptyToBottom : true, // sort empty cell to bottom emptyTo : "bottom", // sort empty cell to bottom
stringTo : "max", // sort strings in numerical column as max value
textExtraction: "simple", textExtraction: "simple",
parsers: {}, parsers: {},
widgets: [], widgets: [],
headers: {}, headers: {},
empties: {},
strings: {},
widthFixed: false, widthFixed: false,
cancelSelection: true, cancelSelection: true,
sortList: [], sortList: [],
@ -142,34 +145,49 @@
return parsers[0]; return parsers[0];
} }
// get sorter, string and empty options for each column from
// metadata, header option or header class name ("sorter-false")
// priority = meta > headers option > header class name
function getData(m, ch, cl, key) {
var val = '';
if (m && m[key]) {
val = m[key];
} else if (ch && ch[key]) {
val = ch[key];
} else if (cl && cl.match(key + '-')) {
// include sorter class name "sorter-text", etc
val = cl.match( new RegExp(key + '-(\\w+)') )[1] || '';
}
return $.trim(val);
}
function buildParserCache(table, $headers) { function buildParserCache(table, $headers) {
if (table.tBodies.length === 0) { return; } // In the case of empty tables if (table.tBodies.length === 0) { return; } // In the case of empty tables
var rows = table.tBodies[0].rows, list, cells, l, h, i, p, parsersDebug = ""; var c = table.config, ch, cl, rows = table.tBodies[0].rows, list, l, h, i,
m = $.metadata ? h.metadata() : false, p, parsersDebug = "";
if (rows[0]) { if (rows[0]) {
list = []; list = [];
cells = rows[0].cells; l = rows[0].cells.length;
l = cells.length;
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
p = false;
h = $($headers[i]); h = $($headers[i]);
if ($.metadata && (h.metadata() && h.metadata().sorter)) { ch = c.headers[i];
p = getParserById(h.metadata().sorter); cl = h.attr('class');
} else if ((table.config.headers[i] && table.config.headers[i].sorter)) { // get column parser
p = getParserById(table.config.headers[i].sorter); p = getParserById( getData(m, ch ,cl, 'sorter') );
} else if (h.attr('class') && h.attr('class').match('sorter-')){ // empty cells behaviour - keeping emptyToBottom for backwards compatibility.
// include sorter class name "sorter-text", etc c.empties[i] = getData(m, ch ,cl, 'empty') || c.emptyTo || (c.emptyToBottom ? 'bottom' : 'top' );
p = getParserById(h.attr('class').match(/sorter-(\w+)/)[1] || ''); // text strings behaviour in numerical sorts
} c.strings[i] = getData(m, ch ,cl, 'string') || c.stringTo || 'max';
if (!p) { if (!p) {
p = detectParserForColumn(table, rows, -1, i); p = detectParserForColumn(table, rows, -1, i);
} }
if (table.config.debug) { if (c.debug) {
parsersDebug += "column:" + i + "; parser:" + p.id + "\n"; parsersDebug += "column:" + i + "; parser:" + p.id + "; string:" + c.strings[i] + '; empty: ' + c.empties[i] + "\n";
} }
list.push(p); list.push(p);
} }
} }
if (table.config.debug) { if (c.debug) {
log(parsersDebug); log(parsersDebug);
} }
return list; return list;
@ -451,24 +469,30 @@
for (i=0; i < l; i++) { for (i=0; i < l; i++) {
c = sortList[i][0]; c = sortList[i][0];
order = sortList[i][1]; order = sortList[i][1];
s = (getCachedSortType(tc.parsers,c) === "text") ? ((order === 0) ? "sortText" : "sortTextDesc") : ((order === 0) ? "sortNumeric" : "sortNumericDesc"); s = getCachedSortType(tc.parsers,c) === "text" ? "Text" : "Numeric";
s += order === 0 ? "" : "Desc";
e = "e" + i; e = "e" + i;
// get max column value (ignore sign) // get max column value (ignore sign)
if (/Numeric/.test(s) && tc.headers[c] && tc.headers[c].string){ if (/Numeric/.test(s) && tc.strings[c]){
for (j=0; j < lc; j++) { for (j=0; j < lc; j++) {
col = Math.abs(parseFloat(cache.normalized[j][c])); col = Math.abs(parseFloat(cache.normalized[j][c]));
mx = Math.max( mx, isNaN(col) ? 0 : col ); mx = Math.max( mx, isNaN(col) ? 0 : col );
} }
dir = (tc.headers[c]) ? tc.string[tc.headers[c].string] || 0 : 0; // sort strings in numerical columns
if (typeof(tc.string[tc.strings[c]]) === 'boolean') {
dir = (order === 0 ? 1 : -1) * (tc.string[tc.strings[c]] ? -1 : 1);
} else {
dir = (tc.strings[c]) ? tc.string[tc.strings[c]] || 0 : 0;
} }
dynamicExp += "var " + e + " = " + s + "(a[" + c + "],b[" + c + "]," + mx + "," + dir + "); "; }
dynamicExp += "var " + e + " = sort" + s + "(a[" + c + "],b[" + c + "]," + c + "," + mx + "," + dir + "); ";
dynamicExp += "if (" + e + ") { return " + e + "; } "; dynamicExp += "if (" + e + ") { return " + e + "; } ";
dynamicExp += "else { "; dynamicExp += "else { ";
} }
// if value is the same keep orignal order // if value is the same keep orignal order
orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0; orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0;
dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];"; dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";
for(i=0; i < l; i++) { for (i=0; i < l; i++) {
dynamicExp += "}; "; dynamicExp += "}; ";
} }
dynamicExp += "return 0; "; dynamicExp += "return 0; ";
@ -480,11 +504,11 @@
} }
// Natural sort modified from: http://www.webdeveloper.com/forum/showthread.php?t=107909 // Natural sort modified from: http://www.webdeveloper.com/forum/showthread.php?t=107909
function sortText(a, b) { function sortText(a, b, col) {
var c = tbl[0].config, cnt = 0, L, t, x;
if (a === b) { return 0; } if (a === b) { return 0; }
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; } var c = tbl[0].config, cnt = 0, L, t, x, e = c.string[ (c.empties[col] || c.emptyTo ) ];
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; } if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : -e || -1; }
if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : e || 1; }
if (c.sortLocaleCompare) { return a.localeCompare(b); } if (c.sortLocaleCompare) { return a.localeCompare(b); }
try { try {
x = /^(\.)?\d/; x = /^(\.)?\d/;
@ -511,11 +535,11 @@
} }
} }
function sortTextDesc(a, b){ function sortTextDesc(a, b, col){
var c = tbl[0].config;
if (a === b) { return 0; } if (a === b) { return 0; }
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; } var c = tbl[0].config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; } if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : e || 1; }
if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : -e || -1; }
if (c.sortLocaleCompare) { return b.localeCompare(a); } if (c.sortLocaleCompare) { return b.localeCompare(a); }
return -sortText(a, b); return -sortText(a, b);
} }
@ -535,21 +559,21 @@
return 0; return 0;
} }
function sortNumeric(a, b, mx, d) { function sortNumeric(a, b, col, mx, d) {
var c = tbl[0].config;
if (a === b) { return 0; } if (a === b) { return 0; }
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; } var c = tbl[0].config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; } if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : -e || -1; }
if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : e || 1; }
if (isNaN(a)) { a = getTextValue(a, mx, d); } if (isNaN(a)) { a = getTextValue(a, mx, d); }
if (isNaN(b)) { b = getTextValue(b, mx, d); } if (isNaN(b)) { b = getTextValue(b, mx, d); }
return a - b; return a - b;
} }
function sortNumericDesc(a, b, mx, d) { function sortNumericDesc(a, b, col, mx, d) {
var c = tbl[0].config;
if (a === b) { return 0; } if (a === b) { return 0; }
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; } var c = tbl[0].config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; } if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : e || 1; }
if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : -e || -1; }
if (isNaN(a)) { a = getTextValue(a, mx, d); } if (isNaN(a)) { a = getTextValue(a, mx, d); }
if (isNaN(b)) { b = getTextValue(b, mx, d); } if (isNaN(b)) { b = getTextValue(b, mx, d); }
return b - a; return b - a;
@ -571,12 +595,12 @@
tbl = $this = $(this).addClass(this.config.tableClass); tbl = $this = $(this).addClass(this.config.tableClass);
// save the settings where they read // save the settings where they read
$.data(this, "tablesorter", c); $.data(this, "tablesorter", c);
// digit sort text location; keeping max+/- for backwards compatibility
c.string = { 'max': 1, 'min': -1, 'max+': 1, 'max-': -1, 'zero': 0, 'none': 0, 'null': 0, 'top': true, 'bottom': false };
// build headers // build headers
$headers = buildHeaders(this); $headers = buildHeaders(this);
// try to auto detect column type, and store in tables config // try to auto detect column type, and store in tables config
c.parsers = buildParserCache(this, $headers); c.parsers = buildParserCache(this, $headers);
// digit sort text location
c.string = { max: 1, 'max+': 1, 'max-': -1, none: 0 };
// build the cache for the tbody cells // build the cache for the tbody cells
cache = buildCache(this); cache = buildCache(this);
// fixate columns if the users supplies the fixedWidth option // fixate columns if the users supplies the fixedWidth option

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "tablesorter", "name": "tablesorter",
"version": "2.1.15", "version": "2.1.16",
"title": "tablesorter", "title": "tablesorter",
"author": { "author": {
"name": "Christian Bach", "name": "Christian Bach",