I am trying to keep pagination in my Angular application using uib-pagination
. I am unable to get proper way to do this.
HTML
<table id="mytable" class="table table-striped">
<thead>
<tr class="table-head">
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in aCandidates">
<th>
<div>{{person}}</div>
</th>
</tr>
</tbody>
</table>
Controller
$scope.totalItems = $scope.aCandidates.length;
$scope.currentPage = 1;
$scope.itemsPerPage = 10;
I am able to see the pagination bar but no action is performed with that and the entire table data is rendered even after giving total-items as 10.
How exactly uib-pagination works and how is the data (in this case aCandidates
) is linked to pagination.
The part you are missing is that you have to have a function to get the current page's data from your entire array. I've added a function called
setPagingData()
to handle this.You can see this in the forked plunker
If you are using
Angular-2
you can try ngx-bootstrap. It has number of bootstrap components that can be integrated withAngular-2
After installing ngx-bootstrap, just try the following
Your html template | pagination.html
Your component | pagination-component.ts
This would render like
For newer versions, change to the following code:
The
<uib-pagination>
tag is no longer supported. It has to be given as an attribute.