-
Notifications
You must be signed in to change notification settings - Fork 6.7k
on-select page invoked twice on totalitems change #1079
Comments
@djkprojects I would prefer a plunker to see what you are talking about, but the change of I don't know if you talk about this design decision as bug or about another situation. |
that's exactly the scenario you've described i.e. "The only case when the change of total-items invokes the on-select-page is when it's change, reduces the number of available pages and the last page is smaller than the current page, and this is by design." and if that's the case then I think on-select-page shouldn't be invoked because logically speaking user hasn't selected any page and it's just the number of items that has changed. on-select-page should only get triggered on user click as its name suggests. Perhaps a new directive would be a good idea: on-total-change? Thanks |
Can you tell us what you are trying to do when a page is changed from user and do not want to do when a page is fixed from the directive? As you may see, this design decision was made since the initial implementation of the directive, and no one has complained. |
yes "on-page-change" definitely makes more sense ;) What I'm trying to do is:
If I remove "on-select-page" from the it works alright but then I'm unable to paginate through the data when changing pages. |
$scope.currentPage = 20; if (resetPage) $scope.currentPage = 1; $http({...}) so if resetPage is set to true after $scope.total = 10; call I'd expect the paginator to stay on page 1 but that's not the case. |
This seems like a very common use case. I hope you understand what I am saying but I cannot do much if you don't provide a plunker. |
Yes, resetPage is true for form submit only: <pagination on-select-page=foo(page)" total-items="total" page="currentPage"> <form data-ng-submit="foo(1, 1)"> I'll try setting up plunker and let you know. Thanks |
What i said is something like this |
...but something more complex (ie when currentpage is 1, just fetch results) |
Here is the plunker: http://plnkr.co/edit/VSVZcO?p=preview Note that when you select any page other than 1 and then submit the form the paginator should reset to 1 but it does only when you press "Go" twice. I've added console.log() so you can see that the values are definitely being set properly. Also, when you remove foo() from on-select-page all works fine. |
I would wait for a better plunker but the code should look like this: http://plnkr.co/edit/4tAKJX?p=preview |
Not sure how this is different from the original version apart from creating a new submit() function as it's still not really working as expected i.e. if you add: if (page == 1) { to fetchData() just to simulate new number of results then select last page and submit the form it will reset to the first page but straight after that another call is made (as a result of new total) and the paginator jumps back to the last page
|
OK. I see the bug, and what is causing it is the order of firing the I 'll try to fix soon, but as a workaround for your case, until the fix is on the master, you can wrap the Thx for reporting, but if we had a plunker from the start we would not have lost a day for this :-) |
HTML Code:
Controller Code:
This scenario causes foo() being called twice due to https://github.com/angular-ui/bootstrap/blob/master/src/pagination/pagination.js#L57 and then https://github.com/angular-ui/bootstrap/blob/master/src/pagination/pagination.js#L45
The change of totalItems shouldn't invoke on-select-page
The text was updated successfully, but these errors were encountered: