I have a view that loads other views. Both views, the parent and the nested ones, have Ajax enabled and have pagination. When a click to go to another page inside a nested view, the parent view is updated. This happens because the events are attached by the outermost parent/view, and not by the closest parent/view. The attached patch seems to fix this bug.

Comments

dawehner’s picture

So it seems to be already token into account that there is a problem with nested views, so i'm wondering why does the current code not work?

James Andres’s picture

The previous patch used jQuery.is() with an object which is not supported until jQuery 1.6. This patch uses object equality comparison, which is valid for DOM elements.

Status: Needs review » Needs work

The last submitted patch, 1877446-3-views-ajax-pager-closest-parent.patch, failed testing.

James Andres’s picture

The correct patch.

zambrey’s picture

I had similar issue with Ajax-loaded Views #1911582: Pager not working on Ajax-loaded Views.
Patch #4 fixed it. Thanks a lot.

infojunkie’s picture

Status: Needs work » Needs review

Re-assigning to test.

dawehner’s picture

Issue tags: +Needs manual testing
+++ b/js/ajax_view.jsundefined
@@ -94,6 +85,8 @@ Drupal.views.ajaxView.prototype.attachPagerAjax = function() {
+  if (!$link.closest('.view').is(this.$view)) return;

+++ b/js/ajax_view.jsundefined
@@ -86,7 +86,7 @@ Drupal.views.ajaxView.prototype.attachPagerAjax = function() {
+  if ($link.closest('.view')[0] != this.$view[0]) return;

Please use {}, as we don't use such code snippets in drupal.

caiosba’s picture

Please check the attached patch, now using {}.

Status: Needs review » Needs work
Issue tags: -Needs manual testing

The last submitted patch, 1877446-3-views-ajax-pager-closest-parent.patch, failed testing.

caiosba’s picture

Status: Needs work » Needs review
Issue tags: +Needs manual testing
acrollet’s picture

Status: Needs review » Needs work

Quick note that this patch completely broke AJAX on a views block with a summary pager attachment using AJAX.

dawehner’s picture

I'm glad that you found this while testing it! You saved a lot of sites just by posting this comment. Thank you!

code-brighton’s picture

Thank you for posting this caiosba I was having this issue with the Load More pager. I had this working fine on a node that had an embedded View. But then (for reasons that I won't bother to explain!) I loaded this node in a nodequeue View and the pager just stopped working with Ajax. This patch got it working. Life saver! Thanks.
I was using Views version 7.x-3.6

James Andres’s picture

Not sure if this is the right place to put this. Here is a fairly note for note 6.x-3.0 backport of 1877446-3-views-ajax-pager-closest-parent.patch.

jelle_s’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.38 KB

Rerolled patch. Can someone explain how to create a summary pager (said to be broken with this patch in #11)

djdevin’s picture

This works for pagers, but I don't think it works for exposed filters. It actually does work for the exposed filters after you change the page via the ajax pager. My guess is because the filter logic is looking at Drupal.settings, which gets changed to the nested view after you load it via ajax.

bpadaria’s picture

Thanks Jelle_S,

Your patch with #15 saved my day

dmsmidt’s picture

#15 works like a charm for pagers! Thanks you! Haven't tested the case mentioned in #16.

Ghostthinker’s picture

I can confirm, this works. Thanks

sadashiv’s picture

Patch at #15 worked for me as well.

Thanks,
Sadashiv.

sergiuteaca’s picture

#15 worked for me as well. Thanks @Jelle_S

darren oh’s picture

Status: Needs review » Reviewed & tested by the community

Patch has been tested by me and others. There may be other bugs left, but this fixes the paging bug.

darren oh’s picture

zalak.addweb’s picture

Issue tags: +ajax pager, +views
sunnygambino’s picture

Confirmed!
#15 worked for me as well. Thanks @Jelle_S

elaine.ong’s picture

Hello,

I have the same problem but I am loading the ajax content with below. I applied above patch but it does not seems to work.
What must I do?

$.ajax({
                url: '/views/ajax',
                type: 'post',
                data: {
                    view_name: 'stores',
                    view_display_id: 'default',
                    view_args: {},
                },
                dataType: 'json',
                success: function (response) {
                    if (response[1] !== undefined) {
                        $('.store-locator-view-wrap').html(response[1].data);
                    }
                }
            });

Thank you in advance.

darren oh’s picture

Title: Ajax pager does not work as expected for nested views » Fix Ajax pager in nested views
StatusFileSize
new1.65 KB

Patch no longer applies. New patch attached.

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -views
Parent issue: » #2960871: Plan for Views 7.x-3.23 release

Committed. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.