Different item count for 1st and other pages

Created on 13 February 2017, over 8 years ago
Updated 14 June 2023, over 2 years ago

In 'Views Show More' module exist useful feature which allows us to change amount of initial items on page.

For example: we can have 3 items when page first loads, and after pressing 'Load more' button we will get like 6 item each time.

I needed this functionality on one of my projects, so here is a patch for that.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇺🇦Ukraine tarasich Kyiv

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇮🇳India himanshu_jhaloya Indore

    Hi I am looking patch for D9 is there any patch for this same issue version 2.0.1

  • 🇮🇳India himanshu_jhaloya Indore

    Created patch for D9

  • 🇩🇰Denmark erik_petra

    Patch at #55 did not apply successfully for me through composer patches, so I fixed it and also fixed some formatting. Patch is for 2.0.1, due to Drupal 10 upgrades.

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇬🇧United Kingdom ChristianSanders

    Unfortunately the latest patch (comment #56) isn't working as desired.

    I have a view with 9 results.

    Initially set to display 7 and load 6 thereafter.

    The initial items of 7 display, but because my view results don't have enough results to reach an additional 6 (9 results, 7 of initial page load, therefore 2 more to load in) the pager doesn't load.

    I've tested by changing initially show 4 items and then 3 thereafter on load. The pager displays, loads in my 3, then no more pager, cause I have 2 items left, not 3.

    This is all tested via AJAX.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update about 2 years ago
    Patch Failed to Apply
  • 🇬🇧United Kingdom ChristianSanders

    Added a patch that solves my comment in 58.

  • 🇬🇧United Kingdom ChristianSanders

    Uploaded the files the wrong way around perviously - sorry!

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update about 2 years ago
    2 pass
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @ChristianSanders could you prepare that as MR perhaps, please?

  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update about 2 years ago
    Not currently mergeable.
  • 🇬🇧United Kingdom ChristianSanders

    @Anybody done - https://git.drupalcode.org/project/views_infinite_scroll/-/merge_request... (hope i've done this correctly - this is my first time contributing a patch via an MR!) Thanks :)

  • Status changed to Needs work about 2 years ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @ChristianSanders. Looking quite good, but there is a conflict left. Perhaps it was based on an older branch? Could you resolve that one?

    Here you can see the resulting diff from the MR: https://git.drupalcode.org/project/views_infinite_scroll/-/merge_request...
    In the end it should be equal to your one?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update about 2 years ago
    2 pass
  • 🇮🇳India himanshu_jhaloya Indore

    I was facing the same issue but checked with views_infinite_scroll-2852080-2852080-different-item-count this branch it is working fine for me thanks @christiansanders

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks. So the last step here seems to be to add test coverage?

  • 🇺🇦Ukraine rsych

    I checked the patch from #61, and there is another bug. My steps:
    1. I set 6 items to show on load
    2. I set 3 items to add on each "load more" click (I use the button)
    Result: when I have 3 items in total, no "load more" button is shown (correct). But after creating another node, I have this behavior: it shows 4 nodes and (here's the error itself) the "load more" button. After clicking on this button, it disappears (without adding any item because everything is already displayed).

  • 🇻🇳Vietnam ypx

    This is an updated patch file to fix the bug reported at #68
    The number of pages needs to be recalculated
    When creating a pager we set total items = current_total_items + (items_per_page - initial_items).

  • First commit to issue fork.
  • Pipeline finished with Canceled
    10 months ago
    Total: 211s
    #352472
  • 🇺🇸United States damienmckenna NH, USA

    I updated the merge request with the changes from #69 (and the latest changes from the 2.0.x branch).

    In my local testing the new options work well, thank you all.

  • Pipeline finished with Success
    10 months ago
    Total: 183s
    #352478
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks, still needs tests (FunctionalJavascript) as last step, right? Who's our hero? 🦸🦸‍♀️

  • Status changed to Needs review 5 months ago
  • First commit to issue fork.
  • 🇳🇱Netherlands anneke_vde

    I added a test for the different initial loading and after first page loading other amount.

  • Pipeline finished with Success
    5 months ago
    Total: 221s
    #472862
  • 🇮🇳India mugesh.s Tamil Nadu

    mugesh.s made their first commit to this issue’s fork.

  • Pipeline finished with Success
    about 1 month ago
    Total: 273s
    #575248
  • 🇮🇳India mugesh.s Tamil Nadu

    Alternative Implementation

    Hi all,

    This approach provides another way to implement the feature without disturbing the current functionality.
    Please review, test, and confirm if this works as expected.

    I’ve also added test coverage to validate the behavior.

    Issue Summary

    This proposal adds a new “Page Control” feature to the Views Infinite Scroll pager plugin, allowing site builders to specify different item counts for:

    • The first page
    • All subsequent pages

    This is useful in UX scenarios where the first page of a listing (e.g., landing pages or featured sections) should show fewer or more items than the rest.

    Proposed resolution

    • ntroduce a checkbox Enable Page Control in the pager settings.
    • When enabled:
      • Hide the existing Items per page field.
      • Show two new number fields:
        • Items for the first page
        • Items for the other pages
    • Modify internal pagination logic to:
      • Set per-page limits conditionally based on current page.
      • Adjust offset and total count logic accordingly.
    • Update getRemainingItems() and getNumberItemsLeft() methods to reflect accurate counts.
    • include #states logic in the options form for dynamic field visibility.

    User interface changes

    A new checkbox and two conditional number fields will be shown in the Views UI under the pager settings.

    Example Use Case

    For example, I want to display only 4 items on the homepage (page 0), but load 2 items on all other pages. This feature enables that flexibility without needing to override views programmatically.

    Video Demonstration

    Here’s a working demo of the feature implemented on my site:

    This feature has been implemented in the branch:
    2852080-Add-Page-Control

    A patch has also been attached here for testing.

    ✅ Please review and test the patch and merge request.
    💬 Feedback and suggestions are most welcome!

  • Merge request !33Resolve #2852080 "Add page control" → (Open) created by Unnamed author
  • Pipeline finished with Success
    about 1 month ago
    Total: 203s
    #575266
Production build 0.71.5 2024