question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loopback and pagination on listView

See original GitHub issue

Hi again, I got a question related to https://github.com/marmelab/ng-admin/issues/414 I’m actually using loopback and the customParams to manage pagination on my listViews:

RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params) {
    if (operation === "getList") {
        // custom pagination params
        if (params._page) {
            params['filter[limit]'] = params._perPage;
            params['filter[skip]'] = (params._page - 1) * params._perPage; //skip is the same os offset
            delete params._page;
            delete params._perPage;
        }
        return {params: params};
    }
});

And my listView is defined like this:

    post.listView()
        .title('Posts List')
        .perPage(10)
        .infinitePagination(false)
        ...
        .listActions(['show', 'edit', 'delete']);

I have access to all Posts while browsing all pages one by one : http://[…]/bower_components/#/Posts/list?page=2, http://[…]/bower_components/#/Posts/list?page=3, etc. But my problem is that the pagination always shows 1 - 10 on 10 on all pages (and not 1-10 on 25 as I expected) - and the buttons of the other pages are not displaying. -> I guess the total-items count must not be equal to the per-page count in this case, but i’m not able to change this in any ways.

If I remove the .perPage(10) attribute, I can see all my 25 Posts (1 - 25 on 25). Do you think it is a problem with loopback, or the latest branch of ng-admin - or should I search for another solution? Help is greatly appreciated 😃 Thanks in advance, Felix.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
emresebatcommented, Mar 23, 2016

Hi

I know this is closed but there is a better solution here loopback#1411 by @abovegradesoftware

Just needs a small addition from your FAQ, adding the CORS header like below

 // Set X-Total-Count for all search requests
  remotes.after('*.find', function (ctx, next) {
    //do this only for ng-admin
    if (ctx.req.headers.appid === 'ng-admin') {
      var filter;
      if (ctx.args && ctx.args.filter) {
        filter = JSON.parse(ctx.args.filter).where;
      }

      if (!ctx.res._headerSent) {
        this.count(filter, function (err, count) {
          //fix for CORS
          ctx.res.set('Access-Control-Expose-Headers', 'x-total-count');
          ctx.res.set('X-Total-Count', count);
          next();
        });
      } else {
        next();
      }
    } else {
      next();
    }
  });
1reaction
F3L1X79commented, Jul 4, 2016

@anagrath : Actually I store the token in the cookies after user login, then I get them in the full request interceptor like this:

app.run(['Restangular', '$rootScope',  '$cookieStore',
        function (RestangularProvider, $rootScope,  $cookieStore) {
            $rootScope.globals = $cookieStore.get('globals') || {};
            if ($rootScope.globals && $rootScope.globals.currentUser) {
                $http.defaults.headers.common['AppId'] = 'ng-admin'; // jshint ignore:line
                $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
            }
            RestangularProvider.addFullRequestInterceptor(function (element, operation, what, url, headers, params) {
                params.access_token = $rootScope.globals.currentUser.token;
                return {params: params};
            });
        }]);

But clearly, @emresebat 's solution is better when you can modify your Loopback’s sources.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Pagination and LoopBack - StrongLoop
Pagination is simply the process of presenting a large set of data to the user one “page”, or one set, at a time....
Read more >
Flutter Pagination Example - Load More on Scroll ListView
Learn about flutter pagination. It's a complete example. Learn how to show the data using listview.builder and load more on scroll.
Read more >
Flutter - Infinite Scrolling Pagination for ListView - YouTube
flutter #flutterui #googleIn this Flutter UI Design Tutorial, We will be taking an in-depth look at Implementing Infinite Scrolling ...
Read more >
Endpoint — pynetbox 7.0.0 documentation - Read the Docs
Queries the 'ListView' of a given endpoint. Returns all objects from an endpoint. Parameters: limit (int,optional) – Overrides the max ...
Read more >
React : How to make pagination in Loopback - Stack Overflow
Loopback have 2 filters for pagination one is skip means how much records you want to skip and limit and how much records...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found