Date filter and updating Pagination


#1

Hello All,

I am working on an app using Ionic 1.3.2 version, a screen has more list of records with various filters like From Date, To Date and Name filters with Pagination (legacy type pagination like 1, 2, 3 …). Have implemented everything separately, no plugins used.

The problem is, when the date filter is applied, records list is not getting updated, have tried the below ways, but no luck, on both methods getting $scope.filtered as undefined in the Controller.

Method1:

    <ion-item ng-repeat="item in (filtered = ( Items | filter:custname 
       |  filter: applyDateFilter('order_date',globalModels.fromdate, globalModels.toDate) 
       | pagination: currentPage * itemsPerPage | limitTo: itemsPerPage))" 
      class="my-item item-text-wrap">

Method 2:

    <ion-item ng-repeat="item in Items | filter:custname 
      | filter: applyDateFilter('order_date',globalModels.fromdate, globalModels.toDate) 
      | pagination: currentPage * itemsPerPage | limitTo: itemsPerPage as filtered" 
    class="my-item item-text-wrap"> 

Whereas for Name filter I have used different approach and it is working, like below in the Controller by adding watch for name using filterFilter(), using which can able to get new list and update pagination.

    $scope.$watch('custname', function(term) {
        if(term != undefined && term != ''){
             $scope.filtered = filterFilter($scope.Items, term); 
             $timeout(function() { 
                $scope.noOfPages = Math.ceil($scope.filtered.length / $scope.itemsPerPage)-1;
             });
        }
      });

I tried the same above logic in date filter, whereas it resulted in performance issue and the app got stuck and blocked further in device whereas in Emulator it was running but the number of records getting increased 10 times more due to continuous loop. I am applying date filter like below

$scope.applyDateFilter = function(items, from, to) {
    return function(items) {
       if(from != '' && to == ''){
           if (orderDt >= fromDt)  {
              return true;
           }
       }
 };
};