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 () {