Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Fix for issue #255 #256

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/md-data-table/scripts/mdTablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function mdTablePagination() {
self.hasPrevious = function () {
return self.page > 1;
};

self.hasFiniteTotal = function(){
return isFinite(self.total);
};

self.last = function () {
self.page = self.pages();
Expand All @@ -67,7 +71,8 @@ function mdTablePagination() {
};

self.pages = function () {
return Math.ceil(self.total / (isZero(self.limit) ? 1 : self.limit));
var n = Math.ceil(self.total / (isZero(self.limit) ? 1 : self.limit));
return isFinite(n) ? n : self.page;
};

self.previous = function () {
Expand Down Expand Up @@ -100,8 +105,11 @@ function mdTablePagination() {
return;
}

// find closest page from previous min
self.page = Math.floor(((self.page * oldValue - oldValue) + newValue) / (isZero(newValue) ? 1 : newValue));
if(!isNaN(newValue) && !isNaN(oldValue)) {
// find closest page from previous min
self.page = Math.floor(((self.page * oldValue - oldValue) + newValue) / (isZero(newValue) ? 1 : newValue));
}

self.onPaginationChange();
});
}
Expand Down
5 changes: 3 additions & 2 deletions app/md-data-table/templates/md-table-pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<md-option ng-repeat="rows in $pagination.options ? $pagination.options : [5, 10, 15]" ng-value="rows">{{rows}}</md-option>
</md-select>

<span class="label">{{$pagination.min() + 1}} - {{$pagination.max()}} {{$pagination.$label['of']}} {{$pagination.total}}</span>
<span class="label">{{$pagination.min() + 1}} - {{$pagination.max()}}</span>
<span class="label" ng-show="$pagination.hasFiniteTotal($pagination.total)">&nbsp;{{$pagination.$label['of']}} {{$pagination.total}}</span>

<md-button class="md-icon-button" type="button" ng-if="$pagination.showBoundaryLinks()" ng-click="$pagination.first()" ng-disabled="!$pagination.hasPrevious()" aria-label="First">
<md-icon md-svg-icon="navigate-first.svg"></md-icon>
Expand All @@ -21,6 +22,6 @@
<md-button class="md-icon-button" type="button" ng-click="$pagination.next()" ng-disabled="$pagination.disableNext()" aria-label="Next">
<md-icon md-svg-icon="navigate-next.svg"></md-icon>
</md-button>
<md-button class="md-icon-button" type="button" ng-if="$pagination.showBoundaryLinks()" ng-click="$pagination.last()" ng-disabled="$pagination.disableNext()" aria-label="Last">
<md-button class="md-icon-button" type="button" ng-if="$pagination.showBoundaryLinks()" ng-click="$pagination.last()" ng-disabled="$pagination.disableNext() || !$pagination.hasFiniteTotal($pagination.total)" aria-label="Last">
<md-icon md-svg-icon="navigate-last.svg"></md-icon>
</md-button>
19 changes: 14 additions & 5 deletions dist/md-data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,10 @@ function mdTablePagination() {
self.hasPrevious = function () {
return self.page > 1;
};

self.hasFiniteTotal = function(){
return isFinite(self.total);
};

self.last = function () {
self.page = self.pages();
Expand All @@ -1206,7 +1210,8 @@ function mdTablePagination() {
};

self.pages = function () {
return Math.ceil(self.total / (isZero(self.limit) ? 1 : self.limit));
var n = Math.ceil(self.total / (isZero(self.limit) ? 1 : self.limit));
return isFinite(n) ? n : self.page;
};

self.previous = function () {
Expand Down Expand Up @@ -1239,8 +1244,11 @@ function mdTablePagination() {
return;
}

// find closest page from previous min
self.page = Math.floor(((self.page * oldValue - oldValue) + newValue) / (isZero(newValue) ? 1 : newValue));
if(!isNaN(newValue) && !isNaN(oldValue)) {
// find closest page from previous min
self.page = Math.floor(((self.page * oldValue - oldValue) + newValue) / (isZero(newValue) ? 1 : newValue));
}

self.onPaginationChange();
});
}
Expand Down Expand Up @@ -1301,7 +1309,8 @@ angular.module('md-table-pagination.html', []).run(['$templateCache', function($
' <md-option ng-repeat="rows in $pagination.options ? $pagination.options : [5, 10, 15]" ng-value="rows">{{rows}}</md-option>\n' +
'</md-select>\n' +
'\n' +
'<span class="label">{{$pagination.min() + 1}} - {{$pagination.max()}} {{$pagination.$label[\'of\']}} {{$pagination.total}}</span>\n' +
'<span class="label">{{$pagination.min() + 1}} - {{$pagination.max()}}</span>\n' +
'<span class="label" ng-show="$pagination.hasFiniteTotal($pagination.total)">&nbsp;{{$pagination.$label[\'of\']}} {{$pagination.total}}</span>\n' +
'\n' +
'<md-button class="md-icon-button" type="button" ng-if="$pagination.showBoundaryLinks()" ng-click="$pagination.first()" ng-disabled="!$pagination.hasPrevious()" aria-label="First">\n' +
' <md-icon md-svg-icon="navigate-first.svg"></md-icon>\n' +
Expand All @@ -1312,7 +1321,7 @@ angular.module('md-table-pagination.html', []).run(['$templateCache', function($
'<md-button class="md-icon-button" type="button" ng-click="$pagination.next()" ng-disabled="$pagination.disableNext()" aria-label="Next">\n' +
' <md-icon md-svg-icon="navigate-next.svg"></md-icon>\n' +
'</md-button>\n' +
'<md-button class="md-icon-button" type="button" ng-if="$pagination.showBoundaryLinks()" ng-click="$pagination.last()" ng-disabled="$pagination.disableNext()" aria-label="Last">\n' +
'<md-button class="md-icon-button" type="button" ng-if="$pagination.showBoundaryLinks()" ng-click="$pagination.last()" ng-disabled="$pagination.disableNext() || !$pagination.hasFiniteTotal($pagination.total)" aria-label="Last">\n' +
' <md-icon md-svg-icon="navigate-last.svg"></md-icon>\n' +
'</md-button>');
}]);
Expand Down