Skip to content

Commit

Permalink
Remove rows from table when using pager ajax #411
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Nov 9, 2013
1 parent e6696b0 commit 3b333d0
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions js/jquery.tablesorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
};

/* debuging utils */
function log(s) {
function log() {
var s = arguments.length > 1 ? Array.prototype.slice.call(arguments) : arguments[0];
if (typeof console !== "undefined" && typeof console.log !== "undefined") {
console.log(s);
} else {
Expand Down Expand Up @@ -201,9 +202,12 @@
var c = table.config,
// update table bodies in case we start with an empty table
tb = c.$tbodies = c.$table.children('tbody:not(.' + c.cssInfoBlock + ')'),
rows, list, l, i, h, ch, p, parsersDebug = "";
rows, list, l, i, h, ch, p, time, parsersDebug = "";
if ( tb.length === 0) {
return c.debug ? log('*Empty table!* Not building a parser cache') : '';
} else if (c.debug) {
time = new Date();
log('Detecting parsers for each column');
}
rows = tb[0].rows;
if (rows[0]) {
Expand Down Expand Up @@ -233,6 +237,7 @@
}
if (c.debug) {
log(parsersDebug);
benchmark("Completed detecting parsers", time);
}
c.parsers = list;
}
Expand Down Expand Up @@ -301,11 +306,12 @@
// init flag (true) used by pager plugin to prevent widget application
function appendToTable(table, init) {
var c = table.config,
b = table.tBodies,
rows = [],
c2 = c.cache,
r, n, totalRows, checkCell, $bk, $tb,
i, j, k, l, pos, appendTime;
wo = c.widgetOptions,
b = table.tBodies,
rows = [],
c2 = c.cache,
r, n, totalRows, checkCell, $bk, $tb,
i, j, k, l, pos, appendTime;
if (isEmptyObject(c2)) { return; } // empty table - fixes #206/#346
if (c.debug) {
appendTime = new Date();
Expand All @@ -322,8 +328,8 @@
for (i = 0; i < totalRows; i++) {
pos = n[i][checkCell];
rows.push(r[pos]);
// removeRows used by the pager plugin
if (!c.appender || !c.removeRows) {
// removeRows used by the pager plugin; don't render if using ajax - fixes #411
if (!c.appender || (c.pager && (!c.pager.removeRows || !wo.pager_removeRows) && !c.pager.ajax)) {
l = r[pos].length;
for (j = 0; j < l; j++) {
$tb.append(r[pos][j]);
Expand All @@ -340,8 +346,8 @@
if (c.debug) {
benchmark("Rebuilt table", appendTime);
}
// apply table widgets
if (!init) { ts.applyWidget(table); }
// apply table widgets; but not before ajax completes
if (!init && !c.appender) { ts.applyWidget(table); }
// trigger sortend
$(table).trigger("sortEnd", table);
$(table).trigger("updateComplete", table);
Expand Down Expand Up @@ -517,7 +523,7 @@
// ensure all sortList values are numeric - fixes #127
s = [ parseInt(v[0], 10), parseInt(v[1], 10) ];
// make sure header exists
o = c.headerList[s[0]];
o = c.$headers[s[0]];
if (o) { // prevents error if sorton array is wrong
c.sortList.push(s);
t = $.inArray(s[1], o.order); // fixes issue #167
Expand Down Expand Up @@ -584,12 +590,13 @@
}
// the user has clicked on an already sorted column
if (ts.isValueInArray(i, c.sortList)) {
// reverse the sorting direction for all tables
// reverse the sorting direction
for (j = 0; j < c.sortList.length; j++) {
s = c.sortList[j];
o = c.headerList[s[0]];
o = c.$headers[s[0]];
if (s[0] === i) {
s[1] = o.order[o.count];
// o.count seems to be incorrect when compared to cell.count
s[1] = o.order[cell.count];
if (s[1] === 2) {
c.sortList.splice(j,1);
o.count = -1;
Expand Down

0 comments on commit 3b333d0

Please sign in to comment.