Support pagination offset/limit

Created on 12 May 2021, over 3 years ago
Updated 3 October 2023, about 1 year ago

Problem/Motivation

Cannot change pagination offset/limit using views. This is one the tentpoles of the JSON:API specitication, yet this module doesn't support it.

Steps to reproduce

Load any view with the `?page[offset]=5&page[limit]=5` querystring and notice that the pagination doesn't change.

Proposed resolution

Add support for the `page[offset]` and `page[limit]` parameters.

💬 Support request
Status

Active

Component

Code

Created by

🇮🇹Italy tegola

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States pookmish

    The suggested patch in #5 does not work in Drupal 10 due to symfony's ->get() method on the input bag. The input bag now requires the returned data to be a scalar (string, number, boolean, etc). But switching to use the ->all() method further breaks due to the Drupal core's view loads the pager via this line in PagerParameters. The patch mentioned in #6 and 7 does not help because it uses the same ->get() method and throws the same error, just in a different place.

  • 🇮🇹Italy Noemi Milan

    The patch is working fine with 9.5.11, but the total count is not correct, since it returns the items per page + 1.

    Does it make sense to use $view->total_rows to populate the count property in meta?

  • 🇺🇸United States pookmish

    I correct myself in #8 (unless it was some dependency update I needed). I've attached the patch that works for me with Drupal 10.1.4.

    @noemi, I wasn't able to reproduce your incorrect count. If I set `?page[limit]=5` the returned number in the meta is 5. What could be more helpful is to have a "total" returned as well. But I wasn't able to find a quick solution for that.

  • 🇮🇹Italy Noemi Milan

    @pookmish I realized the problem with the count is not directly related to this issue, but the use of an offset.
    In short, the total count is equal to the count + the offset and maybe this is the expected behavior.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    6 pass
Production build 0.71.5 2024