cache is now checked properly after delayInit is set true - fixes #346

This commit is contained in:
Mottie 2013-09-30 14:03:12 -05:00
parent ddff43ee4c
commit 8b23e660e7

View File

@ -121,6 +121,14 @@
ts.log = log; ts.log = log;
ts.benchmark = benchmark; ts.benchmark = benchmark;
// $.isEmptyObject from jQuery v1.4
function isEmptyObject(obj) {
for (var name in obj) {
return false;
}
return true;
}
function getElementText(table, node, cellIndex) { function getElementText(table, node, cellIndex) {
if (!node) { return ""; } if (!node) { return ""; }
var c = table.config, var c = table.config,
@ -281,7 +289,7 @@
c2 = c.cache, c2 = c.cache,
r, n, totalRows, checkCell, $bk, $tb, r, n, totalRows, checkCell, $bk, $tb,
i, j, k, l, pos, appendTime; i, j, k, l, pos, appendTime;
if (!c2[0]) { return; } // empty table - fixes #206 if (isEmptyObject(c2)) { return; } // empty table - fixes #206/#346
if (c.debug) { if (c.debug) {
appendTime = new Date(); appendTime = new Date();
} }
@ -606,7 +614,7 @@
var dir = 0, tc = table.config, var dir = 0, tc = table.config,
sortList = tc.sortList, l = sortList.length, bl = table.tBodies.length, sortList = tc.sortList, l = sortList.length, bl = table.tBodies.length,
sortTime, i, k, c, colMax, cache, lc, s, order, orgOrderCol; sortTime, i, k, c, colMax, cache, lc, s, order, orgOrderCol;
if (tc.serverSideSorting || !tc.cache[0]) { // empty table - fixes #206 if (tc.serverSideSorting || isEmptyObject(tc.cache)) { // empty table - fixes #206/#346
return; return;
} }
if (tc.debug) { sortTime = new Date(); } if (tc.debug) { sortTime = new Date(); }
@ -680,7 +688,7 @@
downTime = new Date().getTime(); downTime = new Date().getTime();
return e.target.tagName === "INPUT" ? '' : !c.cancelSelection; return e.target.tagName === "INPUT" ? '' : !c.cancelSelection;
} }
if (c.delayInit && !c.cache) { buildCache(table); } if (c.delayInit && isEmptyObject(c.cache)) { buildCache(table); }
// jQuery v1.2.6 doesn't have closest() // jQuery v1.2.6 doesn't have closest()
var $cell = /TH|TD/.test(this.tagName) ? $(this) : $(this).parents('th, td').filter(':first'), cell = $cell[0]; var $cell = /TH|TD/.test(this.tagName) ? $(this) : $(this).parents('th, td').filter(':first'), cell = $cell[0];
if (!cell.sortDisabled) { if (!cell.sortDisabled) {
@ -768,12 +776,15 @@
checkResort($this, resort, callback); checkResort($this, resort, callback);
}) })
.bind("sorton.tablesorter", function(e, list, callback, init) { .bind("sorton.tablesorter", function(e, list, callback, init) {
var c = table.config;
e.stopPropagation(); e.stopPropagation();
$this.trigger("sortStart", this); $this.trigger("sortStart", this);
// update header count index // update header count index
updateHeaderSortCount(table, list); updateHeaderSortCount(table, list);
// set css for headers // set css for headers
setHeadersCss(table); setHeadersCss(table);
// fixes #346
if (c.delayInit && isEmptyObject(c.cache)) { buildCache(table); }
$this.trigger("sortBegin", this); $this.trigger("sortBegin", this);
// sort the table and append it to the dom // sort the table and append it to the dom
multisort(table); multisort(table);
@ -832,7 +843,11 @@
if (c.debug) { $.data( table, 'startoveralltimer', new Date()); } if (c.debug) { $.data( table, 'startoveralltimer', new Date()); }
// constants // constants
c.supportsTextContent = $('<span>x</span>')[0].textContent === 'x'; c.supportsTextContent = $('<span>x</span>')[0].textContent === 'x';
c.supportsDataObject = (function(version) { version[0] = parseInt(version[0]) ; return (version[0] > 1) || (version[0] == 1 && parseInt(version[1]) >= 4); })($.fn.jquery.split(".")); // removing this in version 3 (only supports jQuery 1.7+)
c.supportsDataObject = (function(version) {
version[0] = parseInt(version[0], 10);
return (version[0] > 1) || (version[0] === 1 && parseInt(version[1], 10) >= 4);
})($.fn.jquery.split("."));
// digit sort text location; keeping max+/- for backwards compatibility // 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 }; c.string = { 'max': 1, 'min': -1, 'max+': 1, 'max-': -1, 'zero': 0, 'none': 0, 'null': 0, 'top': true, 'bottom': false };
// add table theme class only if there isn't already one there // add table theme class only if there isn't already one there