addRows method now works on an empty table. Fixes #450

This commit is contained in:
Mottie 2013-12-03 17:55:25 -06:00
parent d81d64f418
commit 328bba34a7
3 changed files with 30 additions and 24 deletions

View File

@ -612,7 +612,7 @@
}
$t
.unbind('filterStart filterEnd sortEnd disable enable destroy update pageSize '.split(' ').join('.pager '))
.unbind('filterStart filterEnd sortEnd disable enable destroy update updateRows updateAll addRows pageSize '.split(' ').join('.pager '))
.bind('filterStart.pager', function(e, filters) {
p.currentFilters = filters;
})
@ -636,7 +636,7 @@
e.stopPropagation();
destroyPager(table, p);
})
.bind('update.pager', function(e){
.bind('update updateRows updateAll addRows '.split(' ').join('.pager '), function(e){
e.stopPropagation();
hideRows(table, p);
})

View File

@ -814,28 +814,34 @@
})
.bind("addRows.tablesorter", function(e, $row, resort, callback) {
e.stopPropagation();
var i, rows = $row.filter('tr').length,
dat = [], l = $row[0].cells.length,
tbdy = $this.find('tbody').index( $row.parents('tbody').filter(':first') );
// fixes adding rows to an empty table - see issue #179
if (!c.parsers) {
buildParserCache(table);
}
// add each row
for (i = 0; i < rows; i++) {
// add each cell
for (j = 0; j < l; j++) {
dat[j] = c.parsers[j].format( getElementText(table, $row[i].cells[j], j), table, $row[i].cells[j], j );
if (isEmptyObject(c.cache)) {
// empty table, do an update instead - fixes #450
updateHeader(table);
commonUpdate(table, resort, callback);
} else {
var i, rows = $row.filter('tr').length,
dat = [], l = $row[0].cells.length,
tbdy = $this.find('tbody').index( $row.parents('tbody').filter(':first') );
// fixes adding rows to an empty table - see issue #179
if (!c.parsers) {
buildParserCache(table);
}
// add the row index to the end
dat.push(c.cache[tbdy].row.length);
// update cache
c.cache[tbdy].row.push([$row[i]]);
c.cache[tbdy].normalized.push(dat);
dat = [];
// add each row
for (i = 0; i < rows; i++) {
// add each cell
for (j = 0; j < l; j++) {
dat[j] = c.parsers[j].format( getElementText(table, $row[i].cells[j], j), table, $row[i].cells[j], j );
}
// add the row index to the end
dat.push(c.cache[tbdy].row.length);
// update cache
c.cache[tbdy].row.push([$row[i]]);
c.cache[tbdy].normalized.push(dat);
dat = [];
}
// resort using current settings
checkResort($this, resort, callback);
}
// resort using current settings
checkResort($this, resort, callback);
})
.bind("sorton.tablesorter", function(e, list, callback, init) {
var c = table.config;

View File

@ -200,7 +200,7 @@ tsp = ts.pager = {
s = wo.pager_selectors;
c.$table
.unbind('filterStart filterEnd sortEnd disable enable destroy update pageSize '.split(' ').join('.pager '))
.unbind('filterStart filterEnd sortEnd disable enable destroy update updateRows updateAll addRows pageSize '.split(' ').join('.pager '))
.bind('filterStart.pager', function(e, filters) {
p.currentFilters = filters;
})
@ -224,7 +224,7 @@ tsp = ts.pager = {
e.stopPropagation();
tsp.destroyPager(table, c);
})
.on('update.pager', function(e){
.on('update updateRows updateAll addRows '.split(' ').join('.pager '), function(e){
e.stopPropagation();
tsp.hideRows(table, c);
})