angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.28k stars 6.73k forks source link

Update pagination after applying several filters #6557

Closed LaureMonlouis closed 7 years ago

LaureMonlouis commented 7 years ago

Hello ! I did not find the answer I need in previous posts so I will ask here.

Question:

I have quite a big table, with severals colums and I use pagination on my table (uib-pagination). I have some criterias on the table, on for each colum we can say. I would like to uptdate pagination after applying different filters on my table.

HTML code :
<table>
...
<tr class="active" ng-repeat="obj in objects
| typeFilter: type
| filter:{ cam: campagne, cib: cible, arg: argumentaire}
| doublonFilter: doublon
| startFrom:(currentPage-1) * numPerPage
| limitTo:numPerPage">
...
</table>

<ul uib-pagination
class="pagination-sm"
ng-model="currentPage"
total-items="totalItems"
items-per-page="numPerPage"
max-size="maxSize"
force-ellipses="true"
boundary-links="true"
>
</ul>
JS code :
    $scope.$watch('campagne', function (newVal, oldVal) {
      $scope.filtered = filterFilter($scope.objects, {cam: newVal});
      $scope.totalItems = $scope.filtered.length;
      $scope.currentPage = 1;
    }, true);

    $scope.$watch('cible', function (newVal, oldVal) {
      $scope.filtered = filterFilter($scope.objects, {cib: newVal});
      $scope.totalItems = $scope.filtered.length;
      $scope.currentPage = 1;
    }, true);

When I use "campagne" filter first for instance, pagination updates well, but when I use "cible" filter after, this ligne $scope.filtered = filterFilter($scope.objects, newVal); makes that the pagination updates on all table filtered only by the "cible" filter.

I don't know how I can consider all filters at the same time to udpate pagination.

P.S.: $watchGroup does not solve my issue.

Dependencies

Angular : 1.6.4 Angular-ui-bootstrap : 2.5.0

LaureMonlouis commented 7 years ago

I found a way !

    $scope.$watch('campagne', function (newVal, oldVal) {
      $scope.filtered = filterFilter($scope.filtered, {cam: newVal, cib:$scope.cible});
      $scope.totalItems = $scope.filtered.length;
      $scope.currentPage = 1;
    }, true);
WVWillHall commented 7 years ago

I think your issue is with the filter, not pagination. There aren't enough details provided to identify the issue though.

Are your filters 'AND' or 'OR'?

I would try placing each of your filters in its own pipe:

| filter : foo : bar
| filter : boo : far

For science