Skip to content

Commit

Permalink
Refresh last loaded page when size increases
Browse files Browse the repository at this point in the history
  • Loading branch information
Saulis committed Aug 29, 2016
1 parent ecb070b commit 98a236f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions iron-data-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@
size: {
type: Number,
notify: true,
value: 0
value: 0,
observer: '_sizeChanged'
},

/**
Expand Down Expand Up @@ -472,7 +473,6 @@
},

observers: ['_itemsChanged(items.*)',
'_sizeChanged(size)',
'_currentPageChanged(dataSource, _currentPage)',
'_resetData(dataSource, filter.*, sortOrder.*)'
],
Expand Down Expand Up @@ -764,7 +764,6 @@

this.debounce('loading', function() {
this._loadPage(dataSource, page);

if (page + 1 < (this.size / this.pageSize)) {
this._loadPage(dataSource, page + 1);
}
Expand Down Expand Up @@ -852,7 +851,7 @@
}
},

_sizeChanged: function(size) {
_sizeChanged: function(size, oldSize) {
// Optimization: Calling `set` on _cachedItems will reset the scroll position and selections,
// using `push` and `pop` with large changes (more than 1000 items) is a heavy operation
// that jams things up.
Expand All @@ -873,6 +872,14 @@

this.set('_cachedItems', items);
}

// when size increases, old last page needs to be refreshed.
if (size > oldSize) {
var oldLastPage = Math.floor(oldSize / this.pageSize);
if (this._isPageCached(oldLastPage) || oldLastPage === 0) {
this.refreshPage(oldLastPage);
}
}
},

/**
Expand Down

0 comments on commit 98a236f

Please sign in to comment.