When there are multiple views blocks (embed or attachment) on a single page having Infinite scroll as pager settings. Clicking on single view pager leads to scroll other views as well.

Expected behavior: Clicking on individual view pager should lead to scroll only its own view not other views present on the page like normal pagination.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nghai created an issue. See original summary.

nghai’s picture

Issue summary: View changes
albertski’s picture

I had a view inside each row of the main view and I was running into issues. To fix this I had to simply disable AJAX from the main view.

plato1123’s picture

I'm having a similar issue, we have a view that is a list and then we have another "attached" view that is a map up above it. When I enable ajax and click on load more additional items in our list load properly as they should but the map view at the top is also duplicated for each time load more is pressed. I've tried disabling ajax for one or the other and tried a variety of tweaks in the template file but cannot stop this behavior. I should point out this problem happens both with Views Infinite Scroll module or with Views build in ajax load more functionality, so it's not specifically an issue with Views infinite Scroll.

shubhangi1995’s picture

we too had the same issue:
case:
main view - with infinte scroll
second view in the footer of main view - with infinite scroll
solution:
in our case the footer will never reach more than a specific number of nodes hence we removed the infinite scroll for footer view and kept showed the maximum nodes possible which in our case was 10.

Honza Pobořil’s picture

Is this bug also in 1.5 or it was introduced later?

If you will not reply in a ~week I will release 1.6 from the current dev.

shubhangi1995’s picture

sorry for delay i could only reproduce it with 1.5

caitlinreid’s picture

I have created two views: a Page with better exposed filters, and an Attachment.
The filter and the pager (View Infinite Scroll) are inherited in the attachment.

When I click "show more" to expand the first view, items from both views are appended under each, instead of the view to which they belong.

Unfortunately, I get this error with Views Infinite Scroll versions 1.5 and 1.x-dev as well

marthinal’s picture

I have 2 views (2 blocks - same page) and the pager does not appear. I think the problem is that $pager_total has a global scope. See views_infinite_scroll_preprocess_views_infinite_scroll_pager()

  global $pager_page_array, $pager_total;
  $element = $vars['element'];
  $parameters = $vars['parameters'];
  if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
    $options = array(
      'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1),
    );
    $vars['items']['next']['href'] = Url::fromRoute('<none>', [], $options);
  }
  $vars['#cache']['contexts'][] = 'url.query_args';
  $vars['attributes'] = new Attribute([
    'class' => ['js-pager__items', 'pager'],
    'data-drupal-views-infinite-scroll-pager' => $vars['options']['automatically_load_content'] ? 'automatic' : TRUE,
  ]);

We execute InfiniteScroll::updatePageInfo() twice. The second value overrides the first one. The result is that both pagers do not appear because the result is 0 for the second block.

Adding different pager ids does not fix the problem. I'm using Layout Builder.

YahyaAlHamad’s picture

I get around this problem by using separate views.

YahyaAlHamad’s picture

Davy Duthoit’s picture

Thanks to @marthinal comment #9 I have created a patch to work arround this issue.

This was tested on :

  • views_infinite_scroll 8.x-1.6
  • drupal/core 8.7.5
Jérôme Dehorter’s picture

Hi,

Works for me on Drupal 8.7.5 and Views infinite scroll 8.x-1.6.

Thanks.

playful’s picture

When can we expect a release with this fixed?

yusufhm’s picture

Status: Active » Reviewed & tested by the community
playful’s picture

#12 failed to apply on Drupal 8.8.4 with Views Infinite Scroll 8.x-1.7

Ralkeon’s picture

Is this committed to 1.7?

Honza Pobořil’s picture

Could more people confirm it does not break something else, please?

Honza Pobořil’s picture

Status: Reviewed & tested by the community » Needs review
M@ster’s picture

patch can't be applied for 1.7

But I found more simple solutions without patch: just use unique Pager ID
"If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."

nsciacca’s picture

I was having a similar issue where the pager was not being rendered at all on an Attachment on a View block. Both using AJAX and sharing Exposed Filters. The fix was to apply this core patch, which exposed another option under the Pager region that enabled a "Render pager" option.
https://www.drupal.org/project/drupal/issues/2833734#comment-12790527

Neslee Canil Pinto’s picture

Status: Needs review » Needs work

This doesnt work for Drupal 8.8.4 with Views Infinite Scroll 8.x-1.7

debasisnaskar’s picture

Hi,

I have tried using this patch and the infinite scroll works fine for me.
https://www.drupal.org/files/issues/drupal-allow-attachment-pager-283373...
If you are using composer. Then add the below chunk of code.

    "extra": {
        "enable-patching": true,
        "patches": {
            "drupal/core": {
                "views pager fix": "https://www.drupal.org/files/issues/drupal-allow-attachment-pager-2833734-6_0.patch"
            },
            "drupal/ctools": {
                "Views exposed filters missing autosubmit option": "https://www.drupal.org/files/issues/2475595-ctools-autocomplete-fix-24.patch"
            },
    }
}
shubhangi1995’s picture

Assigned: Unassigned » shubhangi1995
SerShevchyk’s picture

I have checked the new version of the module. It looks like all functionality from patch #12 already in the module and we can close the issue.

shubhangi1995’s picture

Assigned: shubhangi1995 » Unassigned
damian.skiba’s picture

This patch is for 8.x-1.7 version. Based on #12.

tapasa’s picture

I have a view page with normal pagination wich I appended another view(a view block) with infinite scroll.
When i'm in the page and I click on the block infinite scroll "View more", both ajax pagers are triggered, so both response actions are executed.
But if I just click the normal pagination it works fine.

I tried every patch but none of them are working for this issue.

And reading the patches comments, I really don't see any relation with the issue title/description.

Edit: After doing some tests, I realized that the problem comes because view container 'js-view-dom-id-xxx' has another view container inside. Maybe is not infinite scroll's issue

fall_0ut’s picture

This patch is for 8.x-1.8 version. Based on #27.

sker101’s picture

Having a new problem now due to this commit in 1.8.

https://www.drupal.org/node/3034528

The Ajax subscriber is now using `$event->getRequest()->query->get('page')` to determine if `infinite_scroll` should be used and which would always be false if there are multiple views on the page.
According to the method `getUpdatedParameters`, the 'page' URL query parameter is a comma-delimited string. It could be something like `0,0,1` when there are multiple views on the page.

pankajsachdeva’s picture

Any update on this issue. I am facing this issue.

I have tried #29 patch. But it doesn't resolve the issue.

Multiple scenarios to reproduce this issue are:

Scenario 1:
Create a page and block with Infinite Scroll. I have attached block view in page Footer attachment. When I am clicking on any of Load More button, both triggering and giving results at same time. I have checked in DOM, that Pager IDs are same for both of views.

Scenario 2:

To make Pager IDs different, I have created page view in different view and used Infinite Scroll with 0 Pager ID setting. And created second view which only contains Block with Infinite Scroll with Pager ID 50. Added this block view in Page Footer attachment. Getting weird behaviour. When clicking on first Load more, it loads random results.

asirjacques’s picture

Hey pankajsachdeva,

I was able to create the behavior you are looking for using views_load_more module instead. This module will let you add a jQuery selector. There is few tricks though.

For example with your scenario 1:

1 - Add the views_load_more pager to the page and the block.

2 - In the block view set the number of items you want to load.

3 - In the page view set the number of items to 0 (no limit) - This will make it bypass this condition:

VLMEventSubscriber.php line 37:

if ($pagerPlugin->getPluginId() == 'load_more' && $pagerPlugin->getCurrentPage() > 0) {

4 - Add a custom view template for your block and add an id to surround rows like this:

{% if rows -%}
    <div id='my-id'>
    {{ rows }}
    </div>
  {% elseif empty -%}

5 - Go back to your view, in the Page display go to Pager > Load more pager, 0 items > ADVANCED OPTIONS.

6 - Add #my-id into Content selector

7 - You can add a custom pager template with nothing inside to remove the main view pager from the page display.

Also, note that only the page view must be ajax or you will have 2 ajax call.

Hope it helps!

lobodacyril’s picture

The patch doesn't work when I use "Automatically Load Content" option because it unbinds all scroll events for window after the first page loading and binds new scroll event only for the current view and then only this view works. I suggest to unbind scroll event only for loading view. Here is my patch.

Notice that the new 2.0.x version was published so I changed this ticket to this branch. The patch should work for both versions but since D8 has EOL, it's prefered to use 2.0 version.

Anybody’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks @lobodacyril - could this please be provided as MR?

Furthermore we need tests for the module to ensure this doesn't break again.