Skip to content

Commit

Permalink
Fix #1192: Prevent notifications from causing a request for page 0
Browse files Browse the repository at this point in the history
(cherry picked from commit a3f64bc)
  • Loading branch information
maier49 authored and Kenneth G. Franqueiro committed Dec 11, 2015
1 parent deb5f9f commit 8b969fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extensions/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions test/intern/extensions/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 8b969fc

Please sign in to comment.