sort empty table

This commit is contained in:
Rob Garrison 2011-08-22 10:00:17 -05:00
parent 8967b5d7f3
commit 59919d6536
7 changed files with 30 additions and 24 deletions

View File

@ -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).
#### 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)
* Fixed a problem where a javascript error would occur when initializing a multi sort on an empty table. Thanks again to Eugene Ivakhiv!

View File

@ -1,5 +1,13 @@
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)
============================

View File

@ -19,7 +19,8 @@
<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() {
@ -32,14 +33,9 @@
// append new html to table body
$("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
// set sorting column and direction, this will sort on the first and third column
$("table")
.trigger("update")
.trigger("sorton",[sorting]);
$("table").trigger("update");
return false;
});

View File

@ -23,7 +23,7 @@
<script id="js">$(function() {
$("table").tablesorter();
$("table").tablesorter({ sortList: [[3,1],[0,0]] });
$("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);
$(this).text(discount);
("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]);
$("table").trigger("updateCell",[this]);
return false;
});

View File

@ -36,7 +36,7 @@
</div>
<p>
<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>
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.

View File

@ -1,6 +1,6 @@
/*
* TableSorter 2.0 - Client-side table sorting with ease!
* Version 2.0.13
* Version 2.0.14
* @requires jQuery v1.2.3
*
* Copyright (c) 2007 Christian Bach
@ -280,12 +280,11 @@
}
function appendToTable(table, cache) {
if (cache.row.length === 0) { return; }
var c = cache,
r = c.row,
n = c.normalized,
totalRows = n.length,
checkCell = (n[0].length - 1),
checkCell = totalRows ? (n[0].length - 1) : 0,
tableBody = $(table.tBodies[0]),
rows = [],
i, j, l, pos, appendTime;
@ -483,12 +482,11 @@
}
function getCachedSortType(parsers, i) {
return parsers[i].type;
return (parsers) ? parsers[i].type : '';
}
/* sorting methods - reverted sorting method back to version 2.0.3 */
function multisort(table,sortList,cache) {
if (cache.row.length === 0) { return cache; } // nothing to sort
var dynamicExp = "var sortWrapper = function(a,b) {",
col, mx = 0, dir = 0, tc = table.config, lc = cache.normalized.length,
l = sortList.length, sortTime, i, j, c, s, e, order, orgOrderCol;
@ -511,7 +509,7 @@
dynamicExp += "else { ";
}
// 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 + "];";
for(i=0; i < l; i++) {
dynamicExp += "}; ";
@ -619,7 +617,7 @@
$headers
.click(function(e){
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.
$this.trigger("sortStart", tbl[0]);
// store exp, for speed
@ -700,6 +698,7 @@
me.config.parsers = buildParserCache(me, $headers);
// rebuild the cache map
cache = buildCache(me);
$this.trigger("sorton", [me.config.sortList]);
}, 1);
})
.bind("updateCell", function(e, cell) {
@ -708,6 +707,7 @@
pos = [(cell.parentNode.rowIndex - 1), cell.cellIndex];
// update cache
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) {
$(this).trigger("sortStart", tbl[0]);

File diff suppressed because one or more lines are too long