angular-ui/ui-grid

PaginationCurrentPage undefined

Open

#5.569 aberto em 20 de jul. de 2016

Ver no GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (2.496 forks)batch import
good first issue

Métricas do repositório

Stars
 (5.395 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

http://plnkr.co/edit/pc6qKAud280qhgNEIE8G?p=preview

Modified the example from external pagination to show the error. Error occurs when changing items per page to 101. This is due to "options.paginationCurrentPage" on line 22256 being undefined when this watch get triggered due to some logic changing the currentPage number because that number wouldn't exist when increasing the items per page.

The other issue being on line 22262. The watch on this line doesn't get triggered because the oldValue (currentPage + items per page) is equal to 101 (100+1) , and the new value would also be 101 (undefined+101).

I originally thought about using $watchGroup on this instead, but because that was introduced in angular 1.3 or so, I decided against it, in order to support older versions.

I am not completely aware of where or why "options.paginationCurrentPage" gets set to undefined, so I ended up inserting a condition in the setShowing() on line 22256.

var setShowing = function () { if(!options.paginationCurrentPage) { options.paginationCurrentPage = 1; } $scope.showingLow = ((options.paginationCurrentPage - 1) * options.paginationPageSize) + 1; $scope.showingHigh = Math.min(options.paginationCurrentPage * options.paginationPageSize, options.totalItems); };

This would cause the math operations to not produce NaN, and also trigger the watch. While I am aware that this functionality is in alpha and this may not be the fix to the root of the issue, it is a workaround that I have started using in the meantime...

Guia do colaborador