How to add pagination in Restangular and Django Rest Framework?

shashisp

In DRF I have added pagination limit to 100 'PAGINATE_BY': 100, since Restangular expects results in array form, I had to use the below meta extractor function in my 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 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 info is not available in controller, how do I paginate if there are more than 100 records available?

jsan

I suppose you could simply 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 usual with Rectangular but Django Rest Framework support pagination from query parameter

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add new values at Django rest framework pagination

How to apply pagination in this case (Django Rest Framework)?

Django rest framework: how to turn off/on pagination in ModelViewSet

How can i set pagination dynamically in Django Rest Framework?

How can i set custom pagination in Django Rest Framework?

How do i configure the django rest framework pagination url

How to implement pagination in a Django and React app without using the REST framework?

Restangular, Django REST and relations

How to add suffix url in Django Rest Framework?

How to add a django rest framework authentication in Route?

How can I use pagination_class in django-rest-framework for my custom pagination class

Django Rest Framework: DRYer pagination for custom actions

Django Rest Framework Pagination Since ID

django rest framework global pagination not working with ListCreateAPIView

Django rest framework validate pagination limit and offset

Django rest framework pagination with custom API view

Pagination not working for viewsets in django rest_framework

Jquery code for Django REST framework pagination

PAGINATION using class APIView in Django Rest Framework

custom pagination of limit and page in Django Rest Framework

Django Rest Framework: turn on pagination on a ViewSet (like ModelViewSet pagination)

How do get custom pagination class working for django rest framework v3.6

How can I leverage builtin pagination for a list_route in the Django Rest Framework?

How to add django rest framework permissions on specific method only ?

Django Rest Framework - How to add custom field in ModelSerializer

How to Add bulk delete by ids in Django Rest Framework

How to add an extra false field in the Django REST framework serializer?

Django Rest Framework : How to add a custom field to the response of the GET request?

How to add an url field to a serializer with Django Rest Framework