0

I am implementing server side pagination in AngularJS following the code at laravel-tricks

I pass pageNumber to the API and it returns the total number of results and other data on that page in the results. The data is then displayed in the table.

How can I generate a list of hrefs for pages dynamically when the results are received ?

Note 1: I have tried ngTable, but it doesn't update the table when the data is changed though it does update the model. Hence resorted to manual pagination since I need a basic pagination only

Note 2: I am not using Bootstrap there for pagination provided by AngularUI is not of any use.

3
  • I don't understand. Why do you need hrefs in this example? The pages are being loaded with AJAX. Are you looking to implement URL routing? Commented Mar 12, 2014 at 15:39
  • I only want to show the pages numbered below the table so that the user may navigate directly to a page Commented Mar 12, 2014 at 15:59
  • 2
    I'd say just make loadPage take the page number, then add <a ng-repeat='page in pages' ng-click='loadPage(page)'>{{page}}</a>. Is there a reason you specifically need to generate href? Commented Mar 12, 2014 at 16:17

1 Answer 1

1

You can do something like this:

//Generate pagination buttons, each with the ng-click directive
<button ng-repeat="pageNumber in [1, 2, 3, 4, 5]" ng-click="goToPage(pageNumber)">
  <span ng-bind="pageNumber"></span>
</button>

Then have a goToPage function in your controller like this:

 $scope.goToPage = function(pageNumber) {    
     $scope.main.page = pageNumber;
     $scope.loadPage();    
 };

NOTE: I just used [1, 2, 3, 4, 5] as an example, but you may want to generate that array in your controller.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks I have a very large number of pages. (in hundreds). How to manage them in the ui ?
Maybe you could use a text input to jump to a page. Maybe post the question here: ux.stackexchange.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.