mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
added usNumberFormat option
This commit is contained in:
parent
930aad6d3a
commit
c15ada9bd9
@ -49,6 +49,7 @@ div.digg {float: right;}
|
||||
.next-up { padding-top: 10px; font-size: 90%; }
|
||||
.narrow-block { width: 50%; margin: 0 auto; }
|
||||
.spacer { height: 800px; }
|
||||
.right { text-align:right; }
|
||||
#pager-demo th.remove { width: 20px; } /* pager demo */
|
||||
#pager-demo button.remove { width: 20px; height: 20px; font-size: 10px; color: #800; }
|
||||
.box { width: 48%; float: left; padding: 0 1%; }
|
||||
|
@ -838,6 +838,30 @@ $(function(){
|
||||
<td><a href="example-option-text-extraction.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="usnumberformat">
|
||||
<td><a href="#" class="toggle2">usNumberFormat</a></td>
|
||||
<td>Boolean</td>
|
||||
<td>true</td>
|
||||
<td>
|
||||
Indicates how tablesorter should deal with a numerical format: <span class="tip"><em>New!</em></span> in v2.1.3.
|
||||
<div class="collapsible">
|
||||
<table class="info"><tbody>
|
||||
<tr>
|
||||
<th><code class="hilight">true</code></th>
|
||||
<td class="right">U.S.</td>
|
||||
<td><code class="hilight">1,234,567.89</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><code class="hilight">false</code></th>
|
||||
<td class="right">German:<br>French:</td>
|
||||
<td><code class="hilight">1.234.567,89</code><br><code class="hilight">1 234 567,89</code></td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="../index.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="widgets">
|
||||
<td>widgets</td>
|
||||
<td>Array</td>
|
||||
|
@ -17,8 +17,9 @@
|
||||
<script>
|
||||
$(function(){
|
||||
$('table').tablesorter({
|
||||
widgets : ['zebra', 'columns'],
|
||||
sortReset : true
|
||||
widgets : ['zebra', 'columns'],
|
||||
usNumberFormat : false,
|
||||
sortReset : true
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* TableSorter 2.1.2 - Client-side table sorting with ease!
|
||||
* TableSorter 2.1.3 - Client-side table sorting with ease!
|
||||
* @requires jQuery v1.2.3
|
||||
*
|
||||
* Copyright (c) 2007 Christian Bach
|
||||
@ -40,6 +40,7 @@
|
||||
sortList: [],
|
||||
headerList: [],
|
||||
dateFormat: "mmddyyyy", // other options: "ddmmyyy" or "yyyymmdd"
|
||||
usNumberFormat: true, // false for German "1.234.567,89" or French "1 234 567,89"
|
||||
onRenderHeader: null,
|
||||
selectorHeaders: 'thead th',
|
||||
selectorRemove: "tr.remove-me",
|
||||
@ -753,13 +754,22 @@
|
||||
widgets.push(widget);
|
||||
};
|
||||
this.formatFloat = function(s) {
|
||||
if (typeof(s) !== 'string') { return s; }
|
||||
if (tbl[0].config.usNumberFormat) {
|
||||
// US Format - 1,234,567.89 -> 1234567.89
|
||||
s = s.replace(/,/g,'');
|
||||
} else {
|
||||
// German Format = 1.234.567,89 -> 1234567.89
|
||||
// French Format = 1 234 567,89 -> 1234567.89
|
||||
s = s.replace(/[\s|\.]/g,'').replace(/,/g,'.');
|
||||
}
|
||||
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(/[,.']/g, '')));
|
||||
return (/^[\-+]?\d*$/).test($.trim(s.replace(/[,.'\s]/g, '')));
|
||||
};
|
||||
this.clearTableBody = function (table) {
|
||||
$(table.tBodies[0]).empty();
|
||||
@ -790,10 +800,10 @@
|
||||
ts.addParser({
|
||||
id: "digit",
|
||||
is: function(s){
|
||||
return $.tablesorter.isDigit(s.replace(/,/g, ""));
|
||||
return $.tablesorter.isDigit(s);
|
||||
},
|
||||
format: function(s){
|
||||
return $.tablesorter.formatFloat(s.replace(/,/g, ""));
|
||||
return $.tablesorter.formatFloat(s);
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -804,7 +814,7 @@
|
||||
return (/^[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]/).test(s); // £$€¤¥¢?.
|
||||
},
|
||||
format: function(s){
|
||||
return $.tablesorter.formatFloat(s.replace(/\,/g,'.').replace(new RegExp(/[^0-9. \-]/g), ""));
|
||||
return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9,. \-]/g), ""));
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
|
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
Loading…
Reference in New Issue
Block a user