How to add pagination in Restangular and Django Rest Framework?

In DRF, I added a pagination limit of up to 100 'PAGINATE_BY': 100, since Restangular expects results in array form, I had to use the following meta extractor function in the angular application module

 var app = angular.module("myapp", ["restangular"].config(function( RestangularProvider){ RestangularProvider.setResponseExtractor(function(response, operation, what, url) { if (operation === "getList") { var newResponse = response.results; newResponse._resultmeta = { "count": response.count, "next": response.next, "previous": response.previous }; return newResponse; } return response; }); }); 

and my controller looks like

 app.controller('DataCtrl',function($scope, Restangular){ var resource = Restangular.all('myapp/api/dataendpoint/'); resource.getList().then(function(data){ $scope.records = data; }); } 

Meta information is not available in the controller, how to paginate if more than 100 entries are available?

+8
angularjs django django-rest-framework pagination restangular
source share
1 answer

I suppose you could just call:

 RestangularProvider.addResponseExtractor(function(data, operation, what, url, response) { if (operation === "getList") { data._resultmeta = { "count": response.count, "next": response.next, "previous": response.previous }; return data; } return response; }); 

and

 var page = 2; var resource = Restangular.all('myapp/api/dataendpoint/'); resource.getList({page: page}).then(function(data){ console.log(data._resultmeta.next ? 'there is more pages' : 'You reach the end'); }); 

I'm not normal with Rectangular , but the Django Rest Framework supports pagination from a query parameter

+2
source share

All Articles