title: how do I make searching/pagination reusable in my application?
body: <p>We decided to use server-side pagination in our application. The implementation is quite simple:</p>
  
  <ul>
  <li><p>suppose we have such a search action on the server side:</p>
  
  <pre><code>[HttpGet]
  public ActionResult GetPeopleByName(String term, Int32 itemsPerPage = 10, Int32 page = 0) {
      var matches = this.people.Where(i =&gt; i.Name.Contains(term));
      return Json(
          data: new {
              people = matches.Skip(itemsPerPage * page).Take(itemsPerPage).OrderBy(i =&gt; i.Name),
              total = matches.Count()
          },
          behavior: JsonRequestBehavior.AllowGet
      );
  }
  </code></pre></li>
  <li><p>on the client we have a <code>subscriptionHolderController</code>:</p>
  
  <pre><code>app.controller('subscriptionHolderController', ['$scope', '$http', function($scope, $http) {
      $scope.matches = [];
      $scope.itemsPerPage = 5;
      $scope.currentPage = 0;
      $scope.searchTerm = '';
  
      // $scope.prevPage = function() { ... };
      // $scope.prevPageDisabled = function() { ... };
      // $scope.nextPage = function() { ... };
      // $scope.nextPageDisabled = function() { ... };
  
      $scope.pageCount = function() { 
          return Math.ceil($scope.totalPages / $scope.itemsPerPage); 
      };
  
      $scope.$watch('currentPage', function() { $scope.search(); });
  
      $scope.search = function() {
          if($scope.searchTerm === '') return;
          // initiate a GET-request with params: { page: $scope.currentPage, term: $scope.searchTerm, itemsPerPage: $scope.itemsPerPage }
      }
      $scope.matchesFound = function () { return $scope.matches.length &gt; 0; }
  }]);
  </code></pre></li>
  </ul>
  
  <p><strong>problem</strong></p>
  
  <p>As the result we have a simple <code>search-box</code>. But our application requires one more type of search with some additional features, it doesn't use search terms and its resulting set <em>should be paginated the same way as it is shown above</em>.</p>
  
  <p>How do I reuse pagination logic for a different types of search? </p>