Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When switching data sources dir-pagination-controls displays wrong number of results #208

Open
ot-brian-mackey opened this issue Jul 29, 2015 · 5 comments

Comments

@ot-brian-mackey
Copy link

The code below displays 37 pages when vm.totalResults is zero. The issue only happens in one scenario:

  1. Display a user with 37 results
  2. Hide that user data with ng-if go to another user with 0 results
  3. User displays 37 results.
  4. Refresh the page (F5 in browser) and now the pagination control goes away as it should as there are 0 results.

Why is this happening?

 <md-list-item dir-paginate="alert in vm.allAlerts | itemsPerPage: vm.pageSize" total-items="vm.totalResults" current-page="vm.currentPage" pagination-id="customerAlerts">

//More code...

  <dir-pagination-controls on-page-change="vm.alertsReload(newPageNumber)" layout="row" layout-align="center center" pagination-id="customerAlerts"></dir-pagination-controls>
@ot-brian-mackey
Copy link
Author

This is happening because paginationService.instances[instanceId].collectionLength returns '37' as can be seen by the return value of paginationService.getCollectionLength(instanceId). collectionLength should have been reset to 0.

I think $watch should be updating the now empty collection and it is not:

if (typeof attrs.totalItems !== 'undefined') {
                    paginationService.setAsyncModeTrue(paginationId);
                    scope.$watch(function() {
                        return $parse(attrs.totalItems)(scope);
                    }, function (result) {
                        if (0 <= result) {
                            paginationService.setCollectionLength(paginationId, result);//not called
                        }
                    });
                } 

@ot-brian-mackey
Copy link
Author

As a workaround I hide the pagination control when there are 0/null results with ng-if.

<dir-pagination-controls ng-if="vm.totalResults" on-page-change="vm.alertsReload(newPageNumber)" layout="row" layout-align="center center" pagination-id="customerAlerts"></dir-pagination-controls>

@ot-brian-mackey
Copy link
Author

After more research I see that dirPaginateDirective does not fire when I show/hide my data by toggling ng-if=. The app.Controller reloads, creating new state, but the said directive does not recompile and capture the new state when there is no data to display.

@michaelbromley
Copy link
Owner

Hi,

Thanks for the detailed report. Is it possible to make a Plunker demo of this?

I cannot tell from what you wrote, but are there multiple dir-paginations being used in the same view? If so, are the pagination-ids resolving to unique values?

@ot-brian-mackey
Copy link
Author

I will work on a plunker reproduction of the issue. This page only has 1 dir-pagination, however there are at least 2 others used in the site. I see three active, uniquely named paginationid's in the paginationService.instances. One uses the __default name, however the one I am experiencing a problem with uses the name customerAlerts unique to this pagination controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants