From 98a236f360ccfaecd7daec5aeb5e84ad34663ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sauli=20T=C3=A4hk=C3=A4p=C3=A4=C3=A4?= Date: Mon, 29 Aug 2016 15:30:15 +0300 Subject: [PATCH] Refresh last loaded page when size increases --- iron-data-table.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/iron-data-table.html b/iron-data-table.html index de945b2..4db5c9f 100644 --- a/iron-data-table.html +++ b/iron-data-table.html @@ -377,7 +377,8 @@ size: { type: Number, notify: true, - value: 0 + value: 0, + observer: '_sizeChanged' }, /** @@ -472,7 +473,6 @@ }, observers: ['_itemsChanged(items.*)', - '_sizeChanged(size)', '_currentPageChanged(dataSource, _currentPage)', '_resetData(dataSource, filter.*, sortOrder.*)' ], @@ -764,7 +764,6 @@ this.debounce('loading', function() { this._loadPage(dataSource, page); - if (page + 1 < (this.size / this.pageSize)) { this._loadPage(dataSource, page + 1); } @@ -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. @@ -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); + } + } }, /**