From 8b969fc14b76f984505bc981bcc21807e8350407 Mon Sep 17 00:00:00 2001 From: Bradley Maier Date: Fri, 23 Oct 2015 10:50:24 -0400 Subject: [PATCH] Fix #1192: Prevent notifications from causing a request for page 0 (cherry picked from commit a3f64bc216be22852037272acc7afcf00c2a59d3) --- extensions/Pagination.js | 2 +- test/intern/extensions/Pagination.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/Pagination.js b/extensions/Pagination.js index bdc516322..2b6760420 100644 --- a/extensions/Pagination.js +++ b/extensions/Pagination.js @@ -436,7 +436,7 @@ define([ if (needsRefresh) { // Refresh the current page to maintain correct number of rows on page - this.gotoPage(Math.min(this._currentPage, Math.ceil(event.totalLength / this.rowsPerPage))); + this.gotoPage(Math.min(this._currentPage, Math.ceil(event.totalLength / this.rowsPerPage)) || 1); } // If we're not updating the whole page, check if we at least need to update status/navigation else if (collection === this._renderedCollection && event.totalLength !== this._total) { diff --git a/test/intern/extensions/Pagination.js b/test/intern/extensions/Pagination.js index cc612fbe2..7cc9561c9 100644 --- a/test/intern/extensions/Pagination.js +++ b/test/intern/extensions/Pagination.js @@ -93,6 +93,22 @@ define([ grid.collection.removeSync(100); testAssertions(100, 10); }); + + test.test('Should not pass 0 to gotoPage when removing last item (#1192)', function() { + var store = createSyncStore({ data: [ { id: 1 } ] }); + grid.set('collection', store); + + var pageNumber; + grid.gotoPage = function (page) { + pageNumber = page; + }; + + store.removeSync(1); + assert.strictEqual(pageNumber, 1, 'Should have refreshed page 1 after removing the last item'); + + store.putSync({ id: 2 }); + assert.strictEqual(pageNumber, 1, 'Should have refreshed page 1 after adding the first item'); + }); }); test.suite('Pagination size selector initialization tests', function () {