I have made the code the display the data into the data-table with the help of HTTP GET Service.
I need to make custom pagination showing only 4 buttons
previous
,1
,2
,next page
.
Note: When user is on page 1 of pagination it should show previous
, 1
, 2
, next page
and if the user is on page 2 it should show previous
, 2
, 3
, next page
and simultaneously like that if any number of data available. If the data is less than 10 only it should display previous
, 1
, next page
and if it exceeds more than 10 it has to follow the above said steps.
Angular JS Code:
<script>
(function(angular) {
'use strict';
angular.module('datatablesSampleApp', ['datatables']).
controller('simpleCtrl', function($scope, $http) {
$http.get("https://jsonplaceholder.typicode.com/users")
.then(function(response) {
$scope.persons = response.data;
});
});
})(angular);
</script>
HTML Code to display the Data-table:
<table datatable="ng" class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Username</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr dt-rows ng-repeat="person in persons">
<td>{{ $index+1 }}</td>
<td>{{ person.name }}</td>
<td>{{ person.username }}</td>
<td>{{ person.email }}</td>
<td>{{ person.phone }}</td>
</tr>
</tbody>
</table>