Here's the script:
I am using an ASP.NET MVC site with Angular JS and Boostrap UI. I have a dynamic ul list populated with data passed through a call to the AngularJS controller, which is filtered in this list through an input field. This list is also controlled by pagination (UI Bootstrap control), which I set to show 10 results per page for a list of 100 items. This list is filtered as the user enters the search field, however I would like the page to refresh as well, so consider the following example:
The list contains 10 pages of elements (100 elements), the user enters text in the search input window, which filters the list to 20 or so, so pagination should be updated from 10 pages to two pages.
I believe that somewhere there should be a $ watch setting, perhaps in the list items after it has been filtered and then refresh the number of pages in the folder, however, I'm pretty new to AngularJS, so someone can explain to me how could this do?
Thank you very much. I posted my code below:
<div data-ng-app="dealsPage"> <input type="text" data-ng-model="cityName" /> <div data-ng-controller="DestinationController"> <ul> <li data-ng-repeat="deals in destinations | filter: cityName | startFrom:currentPage*pageSize | limitTo:pageSize">{{deals.Location}}</li> </ul> <br /> <pagination rotate="true" num-pages="noOfPages" current-page="currentPage" max-size="maxSize" class="pagination-small" boundary-links="true"></pagination> </div>
var destApp = angular.module('dealsPage', ['ui.bootstrap', 'uiSlider']); destApp.controller('DestinationController', function ($scope, $http) { $scope.destinations = {}; $scope.currentPage = 1; $scope.pageSize = 10; $http.get('/Deals/GetDeals').success(function (data) { $scope.destinations = data; $scope.noOfPages = data.length / 10; $scope.maxSize = 5; }); }); destApp.filter('startFrom', function () { return function (input, start) { start = +start;
source share