mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
sort empty table
This commit is contained in:
parent
8967b5d7f3
commit
59919d6536
@ -28,6 +28,13 @@ 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.14 (2011-08-22)
|
||||||
|
|
||||||
|
* Reverted the changes made in 2.0.13 and added checks to prevent errors.
|
||||||
|
* Allowed sorting an empty table which would then automatically sort its contents when the table is updated.
|
||||||
|
* Modified "Update" and "UpdateCell" methods to automatically resort the table using the existing sort.
|
||||||
|
* Updated the [Initializing tablesorter on an empty table](http://mottie.github.com/tablesorter/docs/example-empty-table.html) demo and [Updating a table cell](http://mottie.github.com/tablesorter/docs/example-update-cell.html).
|
||||||
|
|
||||||
#### Version 2.0.13 (2011-08-19)
|
#### Version 2.0.13 (2011-08-19)
|
||||||
|
|
||||||
* Fixed a problem where a javascript error would occur when initializing a multi sort on an empty table. Thanks again to Eugene Ivakhiv!
|
* Fixed a problem where a javascript error would occur when initializing a multi sort on an empty table. Thanks again to Eugene Ivakhiv!
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
TableSorter Change Log
|
TableSorter Change Log
|
||||||
|
|
||||||
|
Version 2.0.14 (2011-08-22)
|
||||||
|
============================
|
||||||
|
|
||||||
|
* Reverted the changes made in 2.0.13 and added checks to prevent errors.
|
||||||
|
* Allowed sorting an empty table which would then automatically sort its contents when the table is updated.
|
||||||
|
* Modified "Update" and "UpdateCell" methods to automatically resort the table using the existing sort.
|
||||||
|
* Updated the [Initializing tablesorter on an empty table](http://mottie.github.com/tablesorter/docs/example-empty-table.html) demo and [Updating a table cell](http://mottie.github.com/tablesorter/docs/example-update-cell.html).
|
||||||
|
|
||||||
Version 2.0.13 (2011-08-19)
|
Version 2.0.13 (2011-08-19)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
<script id="js">$(function() {
|
<script id="js">$(function() {
|
||||||
|
|
||||||
$("table").tablesorter();
|
// Set up empty table with second and first columns pre-sorted
|
||||||
|
$("table").tablesorter({ sortList: [[2,1],[0,0]] });
|
||||||
|
|
||||||
$("#append").click(function() {
|
$("#append").click(function() {
|
||||||
|
|
||||||
@ -32,14 +33,9 @@
|
|||||||
// append new html to table body
|
// append new html to table body
|
||||||
$("table tbody").append(html);
|
$("table tbody").append(html);
|
||||||
|
|
||||||
// resort on the third column
|
|
||||||
var sorting = [[2,1],[0,0]];
|
|
||||||
|
|
||||||
// let the plugin know that we made a update, then
|
// let the plugin know that we made a update, then
|
||||||
// set sorting column and direction, this will sort on the first and third column
|
// set sorting column and direction, this will sort on the first and third column
|
||||||
$("table")
|
$("table").trigger("update");
|
||||||
.trigger("update")
|
|
||||||
.trigger("sorton",[sorting]);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<script id="js">$(function() {
|
<script id="js">$(function() {
|
||||||
|
|
||||||
$("table").tablesorter();
|
$("table").tablesorter({ sortList: [[3,1],[0,0]] });
|
||||||
|
|
||||||
$("table tbody td.discount").click(function() {
|
$("table tbody td.discount").click(function() {
|
||||||
|
|
||||||
@ -31,12 +31,7 @@
|
|||||||
var discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' + ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
|
var discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' + ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
|
||||||
$(this).text(discount);
|
$(this).text(discount);
|
||||||
|
|
||||||
("table").trigger("updateCell",[this]);
|
$("table").trigger("updateCell",[this]);
|
||||||
|
|
||||||
// set sorting column and direction, this will sort on the first and third column
|
|
||||||
var sorting = [[3,1]];
|
|
||||||
// sort on the fourth column
|
|
||||||
$("table").trigger("sorton", [sorting]);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
<strong>Author:</strong> <a class="external" href="http://lovepeacenukes.com">Christian Bach</a><br>
|
<strong>Author:</strong> <a class="external" href="http://lovepeacenukes.com">Christian Bach</a><br>
|
||||||
<strong>Version:</strong> 2.0.12 (<a href="../changelog.txt">changelog</a>)<br>
|
<strong>Version:</strong> 2.0.14 (<a href="../changelog.txt">changelog</a>)<br>
|
||||||
<strong>Licence:</strong>
|
<strong>Licence:</strong>
|
||||||
Dual licensed under <a class="external" href="http://www.opensource.org/licenses/mit-license.php">MIT</a>
|
Dual licensed under <a class="external" href="http://www.opensource.org/licenses/mit-license.php">MIT</a>
|
||||||
or <a class="external" href="http://www.opensource.org/licenses/gpl-license.php">GPL</a> licenses.
|
or <a class="external" href="http://www.opensource.org/licenses/gpl-license.php">GPL</a> licenses.
|
||||||
|
@ -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.13
|
* Version 2.0.14
|
||||||
* @requires jQuery v1.2.3
|
* @requires jQuery v1.2.3
|
||||||
*
|
*
|
||||||
* Copyright (c) 2007 Christian Bach
|
* Copyright (c) 2007 Christian Bach
|
||||||
@ -280,12 +280,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function appendToTable(table, cache) {
|
function appendToTable(table, cache) {
|
||||||
if (cache.row.length === 0) { return; }
|
|
||||||
var c = cache,
|
var c = cache,
|
||||||
r = c.row,
|
r = c.row,
|
||||||
n = c.normalized,
|
n = c.normalized,
|
||||||
totalRows = n.length,
|
totalRows = n.length,
|
||||||
checkCell = (n[0].length - 1),
|
checkCell = totalRows ? (n[0].length - 1) : 0,
|
||||||
tableBody = $(table.tBodies[0]),
|
tableBody = $(table.tBodies[0]),
|
||||||
rows = [],
|
rows = [],
|
||||||
i, j, l, pos, appendTime;
|
i, j, l, pos, appendTime;
|
||||||
@ -483,12 +482,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCachedSortType(parsers, i) {
|
function getCachedSortType(parsers, i) {
|
||||||
return parsers[i].type;
|
return (parsers) ? parsers[i].type : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sorting methods - reverted sorting method back to version 2.0.3 */
|
/* sorting methods - reverted sorting method back to version 2.0.3 */
|
||||||
function multisort(table,sortList,cache) {
|
function multisort(table,sortList,cache) {
|
||||||
if (cache.row.length === 0) { return cache; } // nothing to sort
|
|
||||||
var dynamicExp = "var sortWrapper = function(a,b) {",
|
var dynamicExp = "var sortWrapper = function(a,b) {",
|
||||||
col, mx = 0, dir = 0, tc = table.config, lc = cache.normalized.length,
|
col, mx = 0, dir = 0, tc = table.config, lc = cache.normalized.length,
|
||||||
l = sortList.length, sortTime, i, j, c, s, e, order, orgOrderCol;
|
l = sortList.length, sortTime, i, j, c, s, e, order, orgOrderCol;
|
||||||
@ -511,7 +509,7 @@
|
|||||||
dynamicExp += "else { ";
|
dynamicExp += "else { ";
|
||||||
}
|
}
|
||||||
// if value is the same keep orignal order
|
// if value is the same keep orignal order
|
||||||
orgOrderCol = cache.normalized[0].length - 1;
|
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 += "}; ";
|
||||||
@ -619,7 +617,7 @@
|
|||||||
$headers
|
$headers
|
||||||
.click(function(e){
|
.click(function(e){
|
||||||
totalRows = ($this[0].tBodies[0] && $this[0].tBodies[0].rows.length) || 0;
|
totalRows = ($this[0].tBodies[0] && $this[0].tBodies[0].rows.length) || 0;
|
||||||
if (!this.sortDisabled && totalRows > 0) {
|
if (!this.sortDisabled) {
|
||||||
// Only call sortStart if sorting is enabled.
|
// Only call sortStart if sorting is enabled.
|
||||||
$this.trigger("sortStart", tbl[0]);
|
$this.trigger("sortStart", tbl[0]);
|
||||||
// store exp, for speed
|
// store exp, for speed
|
||||||
@ -700,6 +698,7 @@
|
|||||||
me.config.parsers = buildParserCache(me, $headers);
|
me.config.parsers = buildParserCache(me, $headers);
|
||||||
// rebuild the cache map
|
// rebuild the cache map
|
||||||
cache = buildCache(me);
|
cache = buildCache(me);
|
||||||
|
$this.trigger("sorton", [me.config.sortList]);
|
||||||
}, 1);
|
}, 1);
|
||||||
})
|
})
|
||||||
.bind("updateCell", function(e, cell) {
|
.bind("updateCell", function(e, cell) {
|
||||||
@ -708,6 +707,7 @@
|
|||||||
pos = [(cell.parentNode.rowIndex - 1), cell.cellIndex];
|
pos = [(cell.parentNode.rowIndex - 1), cell.cellIndex];
|
||||||
// update cache
|
// update cache
|
||||||
cache.normalized[pos[0]][pos[1]] = config.parsers[pos[1]].format(getElementText(config, cell, pos[1]), cell);
|
cache.normalized[pos[0]][pos[1]] = config.parsers[pos[1]].format(getElementText(config, cell, pos[1]), cell);
|
||||||
|
$this.trigger("sorton", [config.sortList]);
|
||||||
})
|
})
|
||||||
.bind("sorton", function(e, list) {
|
.bind("sorton", function(e, list) {
|
||||||
$(this).trigger("sortStart", tbl[0]);
|
$(this).trigger("sortStart", tbl[0]);
|
||||||
|
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