mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
numbers inside parenthesis are now treated as a negative
This commit is contained in:
parent
1f7df64e9b
commit
49c67f4c8e
@ -35,6 +35,14 @@ tablesorter can successfully parse and sort many types of data including linked
|
||||
|
||||
View the [complete listing here](https://github.com/Mottie/tablesorter/wiki/Change).
|
||||
|
||||
#### Version 2.1.12 (4/16/2012)
|
||||
|
||||
* Modified digit parser to assume numbers wrapped in parenthesis are negative numbers.
|
||||
* Updated the [Dealing with Digits](example-option-digits.html) demo.
|
||||
* Enhancement from [issue #47](https://github.com/Mottie/tablesorter/issues/47), thanks to [timkingman](https://github.com/timkingman) for sharing the code!
|
||||
* Updated "digit" parser to remove extraneous characters before parsing. This change makes the "digit" parser essentially work the same as the "currency" parser.
|
||||
* Updated some regex to increase parsing speed. See [this jsperf](http://jsperf.com/replace-string-vs-regex/6).
|
||||
|
||||
#### Version 2.1.11 (4/12/2012)
|
||||
|
||||
* Added `emptyToBottom` option which tells tablesorter how you want it to sort empty table cells. Enhancement from [issue #]().
|
||||
|
@ -72,7 +72,7 @@
|
||||
<td>Clark</td>
|
||||
<td>Kent</td>
|
||||
<td>18</td>
|
||||
<td>15.89</td>
|
||||
<td>2.89</td>
|
||||
<td>44.2%</td>
|
||||
<td>-15</td>
|
||||
</tr>
|
||||
@ -90,10 +90,37 @@
|
||||
<td>Bruce</td>
|
||||
<td>Evans</td>
|
||||
<td>56</td>
|
||||
<td>153.19</td>
|
||||
<td>$153.19</td>
|
||||
<td>23%</td>
|
||||
<td>+9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A256</td>
|
||||
<td>John</td>
|
||||
<td>Clark</td>
|
||||
<td>44</td>
|
||||
<td>($19.89)</td>
|
||||
<td>25.1%</td>
|
||||
<td>(5)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A23</td>
|
||||
<td>Elvis</td>
|
||||
<td>Presley</td>
|
||||
<td>24</td>
|
||||
<td>($9.99)</td>
|
||||
<td>50%</td>
|
||||
<td>(22)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A10</td>
|
||||
<td>Frank</td>
|
||||
<td>Carter</td>
|
||||
<td>40</td>
|
||||
<td>-12.99</td>
|
||||
<td>20%</td>
|
||||
<td>(6)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
|
||||
|
@ -673,7 +673,7 @@
|
||||
<tr><th><code class="hilight">sorter: false</code></th><td>disable sort for this column.</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "text"</code></th><td>Sort alpha-numerically.</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "digit"</code></th><td>Sort numerically.</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "currency"</code></th><td>Sort by currency value (supports "£$€").</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "currency"</code></th><td>Sort by currency value (supports "£$€¤¥¢").</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "ipAddress"</code></th><td>Sort by IP Address.</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "url"</code></th><td>Sort by url.</td></tr>
|
||||
<tr><th><code class="hilight">sorter: "isoDate"</code></th><td>Sort by ISO date (YYYY-MM-DD or YYYY/MM/DD).</td></tr>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* TableSorter 2.1.11 - Client-side table sorting with ease!
|
||||
* TableSorter 2.1.12 - Client-side table sorting with ease!
|
||||
* @requires jQuery v1.2.6+
|
||||
*
|
||||
* Copyright (c) 2007 Christian Bach
|
||||
@ -18,7 +18,7 @@
|
||||
$.extend({
|
||||
tablesorter: new function(){
|
||||
|
||||
this.version = "2.1.11";
|
||||
this.version = "2.1.12";
|
||||
|
||||
var parsers = [], widgets = [], tbl;
|
||||
this.defaults = {
|
||||
@ -768,13 +768,16 @@
|
||||
// French Format = 1 234 567,89 -> 1234567.89
|
||||
s = s.replace(/[\s|\.]/g,'').replace(/,/g,'.');
|
||||
}
|
||||
if(/^\s*\([.\d]+\)/.test(s)) {
|
||||
s = s.replace(/^\s*\(/,'-').replace(/\)/,'');
|
||||
}
|
||||
var i = parseFloat(s);
|
||||
// return the text instead of zero
|
||||
return isNaN(i) ? $.trim(s) : i;
|
||||
};
|
||||
this.isDigit = function(s) {
|
||||
// replace all unwanted chars and match.
|
||||
return (/^[\-+]?\d*$/).test($.trim(s.replace(/[,.'\s]/g, '')));
|
||||
return (/^[\-+(]?\d*[)]?$/).test($.trim(s.replace(/[,.'\s]/g, '')));
|
||||
};
|
||||
this.clearTableBody = function (table) {
|
||||
$(table.tBodies[0]).empty();
|
||||
@ -808,7 +811,7 @@
|
||||
return $.tablesorter.isDigit(s);
|
||||
},
|
||||
format: function(s){
|
||||
return $.tablesorter.formatFloat(s);
|
||||
return $.tablesorter.formatFloat(s.replace(/[^0-9,. \-()]/g, ""));
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -816,10 +819,10 @@
|
||||
ts.addParser({
|
||||
id: "currency",
|
||||
is: function(s){
|
||||
return (/^[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]/).test(s); // £$€¤¥¢?.
|
||||
return (/^\(?[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]/).test(s); // £$€¤¥¢?.
|
||||
},
|
||||
format: function(s){
|
||||
return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9,. \-]/g), ""));
|
||||
return $.tablesorter.formatFloat(s.replace(/[^0-9,. \-()]/g, ""));
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -852,7 +855,7 @@
|
||||
return (/^(https?|ftp|file):\/\/$/).test(s);
|
||||
},
|
||||
format: function(s) {
|
||||
return $.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//), ''));
|
||||
return $.trim(s.replace(/(https?|ftp|file):\/\//, ''));
|
||||
},
|
||||
type: "text"
|
||||
});
|
||||
@ -863,7 +866,7 @@
|
||||
return (/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/).test(s);
|
||||
},
|
||||
format: function(s) {
|
||||
return $.tablesorter.formatFloat((s !== "") ? new Date(s.replace(new RegExp(/-/g), "/")).getTime() : "");
|
||||
return $.tablesorter.formatFloat((s !== "") ? new Date(s.replace(/-/g, "/")).getTime() : "");
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -871,10 +874,10 @@
|
||||
ts.addParser({
|
||||
id: "percent",
|
||||
is: function(s) {
|
||||
return (/\%$/).test($.trim(s));
|
||||
return (/\%\)?$/).test($.trim(s));
|
||||
},
|
||||
format: function(s) {
|
||||
return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g), ""));
|
||||
return $.tablesorter.formatFloat(s.replace(/%/g, ""));
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -882,7 +885,7 @@
|
||||
ts.addParser({
|
||||
id: "usLongDate",
|
||||
is: function(s) {
|
||||
return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));
|
||||
return s.match(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/);
|
||||
},
|
||||
format: function(s) {
|
||||
return $.tablesorter.formatFloat(new Date(s).getTime());
|
||||
|
4
js/jquery.tablesorter.min.js
vendored
4
js/jquery.tablesorter.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tablesorter",
|
||||
"version": "2.1.11",
|
||||
"version": "2.1.12",
|
||||
"title": "tablesorter",
|
||||
"author": {
|
||||
"name": "Christian Bach",
|
||||
|
Loading…
Reference in New Issue
Block a user