4

I'm using the very good table library Smart-table to display my data.

I am using a custom pagination template. I would however like to be able to set the page to the last one so I could see the last item added.

This is the pagination.html :

<nav ng-if="pages.length >= 2">
<ul class="pagination">
    <li>
        <a ng-click="selectPage(1)">First</a>
    </li>
    <li>
        <a ng-click="selectPage(currentPage - 1)">&lt;</a>
    </li>
    <li>
        <a><page-select></page-select> of {{numPages}}</a>
    </li>
    <li>
        <a ng-click="selectPage(currentPage + 1)">&gt;</a>
    </li>
    <li>
        <a ng-click="selectPage(numPages)">Last</a>
    </li>
</ul>

And this is the directive

angular.module('myApp')
.directive('pageSelect', function() {
  return {
    restrict: 'E',
    template: '<input type="text" class="select-page" ng-model="inputPage" ng-change="selectPage(inputPage)">',
    link: function(scope, element, attrs) {
      scope.$watch('currentPage', function(c) {
        scope.inputPage = c;
      });
    }
  }
});
ErEcTuS
  • 777
  • 1
  • 14
  • 33

1 Answers1

0

Just call the function selectPage(numPages) from your controller.

Harish
  • 490
  • 2
  • 11
  • 19