angularjs - How to add pagination in Restangular and Django Rest Framework? -
in drf have added pagination limit 100 'paginate_by': 100,
since restangular expects results in array form, had use below meta extractor function in angular app 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 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 info not available in controller, how paginate if there more 100 records available?
i suppose 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 more pages' : 'you reach end'); });
i'm not usual rectangular
django rest framework support pagination query parameter
Comments
Post a Comment