mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
added emptyTo and stringTo options
This commit is contained in:
parent
a5607ae960
commit
ee173ba65a
@ -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).
|
||||
|
||||
#### 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)
|
||||
|
||||
* 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).
|
||||
* 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).
|
||||
|
||||
|
@ -20,7 +20,8 @@
|
||||
<script id="js">$(function() {
|
||||
// call the tablesorter plugin
|
||||
$("table").tablesorter({
|
||||
emptyToBottom: true
|
||||
// default "emptyTo"
|
||||
emptyTo: 'bottom'
|
||||
});
|
||||
});</script>
|
||||
|
||||
@ -28,10 +29,9 @@
|
||||
$(function(){
|
||||
$('select').change(function(){
|
||||
var t = $('table'),
|
||||
etb = $(this).val(),
|
||||
v = (etb === 'true') ? true : (etb === 'false' ? false : null);
|
||||
t[0].config.emptyToBottom = v;
|
||||
t.trigger("sorton", [t[0].config.sortList]);
|
||||
v = $(this).val();
|
||||
t[0].config.emptyTo = v;
|
||||
t.trigger("update");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@ -47,26 +47,35 @@ $(function(){
|
||||
|
||||
<p class="tip">
|
||||
<em>NOTE!</em>
|
||||
Set the <code class="hilight">emptyToBottom</code> selector below:
|
||||
Set the <code class="hilight">emptyTo</code> selector below:
|
||||
<ul>
|
||||
<li>true - sort empty table cells to the bottom.</li>
|
||||
<li>false - sort empty table cells to the top.</li>
|
||||
<li>null - sort empty table cells as if the cell has the value equal to zero.</li>
|
||||
<li><code class="hilight">top</code> - sort empty table cells to the top.</li>
|
||||
<li><code class="hilight">bottom</code> - sort empty table cells to the bottom.</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>
|
||||
</p>
|
||||
|
||||
<h1>Demo</h1>
|
||||
|
||||
Set <code class="hilight">emptyToBottom</code> option: <select>
|
||||
<option>true</option>
|
||||
<option>false</option>
|
||||
<option>null</option>
|
||||
Set <code class="hilight">emptyTo</code> option: <select>
|
||||
<option>bottom</option>
|
||||
<option>top</option>
|
||||
<option>zero</option>
|
||||
</select>
|
||||
|
||||
<div id="demo"><table class="tablesorter">
|
||||
<thead>
|
||||
<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>Last Name</th>
|
||||
<th>Age</th>
|
||||
@ -150,6 +159,7 @@ Set <code class="hilight">emptyToBottom</code> option: <select>
|
||||
</tr>
|
||||
</tbody>
|
||||
</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>
|
||||
<div id="javascript">
|
||||
|
@ -23,13 +23,16 @@
|
||||
<script id="js">$(function() {
|
||||
// call the tablesorter plugin
|
||||
$("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: {
|
||||
5: { sorter: "digit", string: "max+" }, // non-numeric content is treated as a MAX value
|
||||
6: { sorter: "digit", string: "max-" }, // non-numeric content is treated as a MIN value
|
||||
7: { sorter: "digit", string: "max+" }, // non-numeric content is treated as a MAX 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)
|
||||
1: { sorter: "digit", empty : "top" }, // sort empty cells to the top
|
||||
2: { 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
|
||||
}
|
||||
|
||||
});
|
||||
});</script>
|
||||
</head>
|
||||
@ -46,10 +49,27 @@
|
||||
<em>NOTE!</em>
|
||||
<ul>
|
||||
<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>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>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>Sort columns five through eight to see how the sort has changed. Note that the text is sorted separately from the numeric values.</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>Overall <code class="hilight">stringTo</code> option added in version 2.1.16.</li>
|
||||
<li>String options 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>
|
||||
</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>
|
||||
</p>
|
||||
|
||||
@ -58,137 +78,126 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Account #</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Age</th>
|
||||
<th>Difference</th>
|
||||
<th>5: Ratings (max+)</th>
|
||||
<th>6: Ratings (max-)</th>
|
||||
<th>7: Change (max+)</th>
|
||||
<th>8: Change (max-)</th>
|
||||
<th>9: Change (none)</th>
|
||||
<th>3: Ratings (max)</th>
|
||||
<th>4: Ratings (min)</th>
|
||||
<th class="string-max">5: Change (max)</th>
|
||||
<th class="string-min">6: Change (min)</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>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>A43</td>
|
||||
<td>Peter</td>
|
||||
<td>Parker</td>
|
||||
<td>28</td>
|
||||
<td>-35</td>
|
||||
<td>01</td>
|
||||
<td>01</td>
|
||||
<td>-.1</td>
|
||||
<td>-.1</td>
|
||||
<td>-.1</td>
|
||||
<td>-.1</td>
|
||||
<td>-.1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A255</td>
|
||||
<td>John</td>
|
||||
<td>Hood</td>
|
||||
<td>33</td>
|
||||
<td>33</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A33</td>
|
||||
<td>Clark</td>
|
||||
<td>Kent</td>
|
||||
<td>18</td>
|
||||
<td>2</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A1</td>
|
||||
<td>Bruce</td>
|
||||
<td>Almighty</td>
|
||||
<td>45</td>
|
||||
<td>-5</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A102</td>
|
||||
<td>Bruce</td>
|
||||
<td>Evans</td>
|
||||
<td>22</td>
|
||||
<td>99</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A10</td>
|
||||
<td>James</td>
|
||||
<td>Sullivan</td>
|
||||
<td>46</td>
|
||||
<td>-1</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A02</td>
|
||||
<td>Bruce</td>
|
||||
<td>Campbell</td>
|
||||
<td>32</td>
|
||||
<td>0</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A55</td>
|
||||
<td>Frank</td>
|
||||
<td>Evans</td>
|
||||
<td>51</td>
|
||||
<td>44</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A87</td>
|
||||
<td>Joe</td>
|
||||
<td>Smith</td>
|
||||
<td>24</td>
|
||||
<td>04</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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A012</td>
|
||||
<td>Mike</td>
|
||||
<td>Wazowski</td>
|
||||
<td>21</td>
|
||||
<td>-24</td>
|
||||
<td></td>
|
||||
<td>NR</td>
|
||||
<td>NR</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
|
@ -562,18 +562,26 @@
|
||||
<td><a href="example-option-debug.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="emptytobottom">
|
||||
<td><a href="#" class="toggle2">emptyToBottom</a></td>
|
||||
<td>Boolean</td>
|
||||
<td>true</td>
|
||||
<tr id="emptyto">
|
||||
<td><a href="#" class="toggle2">emptyTo</a></td>
|
||||
<td>String</td>
|
||||
<td>"bottom"</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">
|
||||
<ul>
|
||||
<li><code class="hilight">true</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">null</code> - sort empty table cells as if the cell has the lowest value (less than "a" and "0").</li>
|
||||
<li><code class="hilight">bottom</code> - sort empty table cells to the bottom.</li>
|
||||
<li><code class="hilight">top</code> - sort empty table cells to the top.</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>
|
||||
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>
|
||||
</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>
|
||||
</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">
|
||||
<td>tableClass</td>
|
||||
<td>String</td>
|
||||
|
@ -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+
|
||||
*
|
||||
* Copyright (c) 2007 Christian Bach
|
||||
@ -18,7 +18,7 @@
|
||||
$.extend({
|
||||
tablesorter: new function(){
|
||||
|
||||
this.version = "2.1.15";
|
||||
this.version = "2.1.16";
|
||||
|
||||
var parsers = [], widgets = [], tbl;
|
||||
this.defaults = {
|
||||
@ -33,11 +33,14 @@
|
||||
sortLocaleCompare: false,
|
||||
sortReset: 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",
|
||||
parsers: {},
|
||||
widgets: [],
|
||||
headers: {},
|
||||
empties: {},
|
||||
strings: {},
|
||||
widthFixed: false,
|
||||
cancelSelection: true,
|
||||
sortList: [],
|
||||
@ -142,34 +145,49 @@
|
||||
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) {
|
||||
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]) {
|
||||
list = [];
|
||||
cells = rows[0].cells;
|
||||
l = cells.length;
|
||||
l = rows[0].cells.length;
|
||||
for (i = 0; i < l; i++) {
|
||||
p = false;
|
||||
h = $($headers[i]);
|
||||
if ($.metadata && (h.metadata() && h.metadata().sorter)) {
|
||||
p = getParserById(h.metadata().sorter);
|
||||
} else if ((table.config.headers[i] && table.config.headers[i].sorter)) {
|
||||
p = getParserById(table.config.headers[i].sorter);
|
||||
} else if (h.attr('class') && h.attr('class').match('sorter-')){
|
||||
// include sorter class name "sorter-text", etc
|
||||
p = getParserById(h.attr('class').match(/sorter-(\w+)/)[1] || '');
|
||||
}
|
||||
ch = c.headers[i];
|
||||
cl = h.attr('class');
|
||||
// get column parser
|
||||
p = getParserById( getData(m, ch ,cl, 'sorter') );
|
||||
// empty cells behaviour - keeping emptyToBottom for backwards compatibility.
|
||||
c.empties[i] = getData(m, ch ,cl, 'empty') || c.emptyTo || (c.emptyToBottom ? 'bottom' : 'top' );
|
||||
// text strings behaviour in numerical sorts
|
||||
c.strings[i] = getData(m, ch ,cl, 'string') || c.stringTo || 'max';
|
||||
if (!p) {
|
||||
p = detectParserForColumn(table, rows, -1, i);
|
||||
}
|
||||
if (table.config.debug) {
|
||||
parsersDebug += "column:" + i + "; parser:" + p.id + "\n";
|
||||
if (c.debug) {
|
||||
parsersDebug += "column:" + i + "; parser:" + p.id + "; string:" + c.strings[i] + '; empty: ' + c.empties[i] + "\n";
|
||||
}
|
||||
list.push(p);
|
||||
}
|
||||
}
|
||||
if (table.config.debug) {
|
||||
if (c.debug) {
|
||||
log(parsersDebug);
|
||||
}
|
||||
return list;
|
||||
@ -451,24 +469,30 @@
|
||||
for (i=0; i < l; i++) {
|
||||
c = sortList[i][0];
|
||||
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;
|
||||
// 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++) {
|
||||
col = Math.abs(parseFloat(cache.normalized[j][c]));
|
||||
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 += "else { ";
|
||||
}
|
||||
// if value is the same keep orignal order
|
||||
orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0;
|
||||
dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";
|
||||
for(i=0; i < l; i++) {
|
||||
for (i=0; i < l; i++) {
|
||||
dynamicExp += "}; ";
|
||||
}
|
||||
dynamicExp += "return 0; ";
|
||||
@ -480,11 +504,11 @@
|
||||
}
|
||||
|
||||
// Natural sort modified from: http://www.webdeveloper.com/forum/showthread.php?t=107909
|
||||
function sortText(a, b) {
|
||||
var c = tbl[0].config, cnt = 0, L, t, x;
|
||||
function sortText(a, b, col) {
|
||||
if (a === b) { return 0; }
|
||||
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; }
|
||||
if (b === '' && 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 (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); }
|
||||
try {
|
||||
x = /^(\.)?\d/;
|
||||
@ -511,11 +535,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function sortTextDesc(a, b){
|
||||
var c = tbl[0].config;
|
||||
function sortTextDesc(a, b, col){
|
||||
if (a === b) { return 0; }
|
||||
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; }
|
||||
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; }
|
||||
var c = tbl[0].config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
|
||||
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); }
|
||||
return -sortText(a, b);
|
||||
}
|
||||
@ -535,21 +559,21 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
function sortNumeric(a, b, mx, d) {
|
||||
var c = tbl[0].config;
|
||||
function sortNumeric(a, b, col, mx, d) {
|
||||
if (a === b) { return 0; }
|
||||
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; }
|
||||
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; }
|
||||
var c = tbl[0].config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
|
||||
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(b)) { b = getTextValue(b, mx, d); }
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function sortNumericDesc(a, b, mx, d) {
|
||||
var c = tbl[0].config;
|
||||
function sortNumericDesc(a, b, col, mx, d) {
|
||||
if (a === b) { return 0; }
|
||||
if (a === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? 1 : -1; }
|
||||
if (b === '' && c.emptyToBottom !== null) { return c.emptyToBottom ? -1 : 1; }
|
||||
var c = tbl[0].config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
|
||||
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(b)) { b = getTextValue(b, mx, d); }
|
||||
return b - a;
|
||||
@ -571,12 +595,12 @@
|
||||
tbl = $this = $(this).addClass(this.config.tableClass);
|
||||
// save the settings where they read
|
||||
$.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
|
||||
$headers = buildHeaders(this);
|
||||
// try to auto detect column type, and store in tables config
|
||||
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
|
||||
cache = buildCache(this);
|
||||
// fixate columns if the users supplies the fixedWidth option
|
||||
|
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.15",
|
||||
"version": "2.1.16",
|
||||
"title": "tablesorter",
|
||||
"author": {
|
||||
"name": "Christian Bach",
|
||||
|
Loading…
Reference in New Issue
Block a user