Score:0

Nested views ajax pagination

in flag

I am using Drupal 9 and views_field_view to embed a "child" view within a "parent" view. Because there are multiple rows in the parent view, I end up with multiple of the same "child" view being rendered. This prevents the "pagination" from rendering because the "pager id" is the same for the multiple rendered child views.

I am able to circumvent that render issue by programmatically setting the pager id. See code below.

use Drupal\views\ViewExecutable;

function hook_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  
  if ($view->id() == '<view_id>') {
    $unique_id = $view->args[0]; // argument that is a unique ID
    $view->pager->options['id'] = $unique_id;
  }
}

By using the above code in a module, the child view's pager now appears. However, clicking the pager numbers or buttons results in the parent view updating instead of the child view.

How can I change the pager for the "child" view so that it updates the child view instead of the parent?

It seems that I need to properly initialize the pager or alter the jquery so it updates the child view instead of the parent? How might I go about doing that?


Here are a some things I've been looking into, but so far have not helped:

  1. Drupal 7 views fix - not applicable since views moved into core?
  2. Views load more issue, Views show more module, Views infinite scroll issue
  3. Within the views_field_view module it seems that it attempts to set a unique id for the pager before using the following $view->initPager(); to initialize the pager. However debugging shows that the ID that is set does not get applied on to the $view. Did something maybe change with initPager? (though the API doesn't make any indication that it has)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.