I'm trying to find a way for a pager plugin to provide an option to show the pager above the page instead of below, but I can't find any way to get that working. This is for a date pager, since almost anyone (including me) expects date/calendar pagers to appear at the top of the page.

While trying to find a solution for this I stumbled across the area plugin type. I'm wondering if it might be possible to create an area plugin for the pager placement so people could put the pager above, below, or both above and below their content. Not sure how do-able this is currently, since the pager placement seems to be pretty much hard-wired into Views. Any thoughts on the feasibility/wisdom of going this route? And if it makes sense, does this seem like something that should go in Views itself rather than as a separate project?

Comments

merlinofchaos’s picture

The pager could put data into $view->attachment_before perhaps?

karens’s picture

I tried that, but it isn't working. Maybe because there is nothing else there or it is not marked to display if empty. I tried all kinds of places, pre_view, pre_render, post_view, post_render. Couldn't find a way to get it working.

karens’s picture

Anyway, since it is non-trivial to do, I thought it might make sense for Views to make it easier. It seems like a pretty common sort of thing to do.

merlinofchaos’s picture

Really? Anything in $view->attachment_before or _after should automatically be part of the view. If it's not, that's kind of a bug.

karens’s picture

OK, I finally found a way to get this working. I can find no way for the pager to move itself, but a module can do it. So I had the pager add an identifer to the view, then used the following code in a module to find views that have the identifier and move the pager. The pager provides an option to the user to put the pager on 'top', 'bottom' or 'both', and this code moves it. We need the identifier because otherwise we would be moving ALL pagers.

Posting this so others can see how to do it because I spent hours going down rabbit holes that didn't work.

/**
 * Jump in and move the pager.
 */
function date_views_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  if (!empty($view->date_info) && !empty($view->date_info->date_pager_position)) {
    switch ($view->date_info->date_pager_position) {
      case 'top':
        $vars['attachment_before'] .= $vars['pager'];
        $vars['pager'] = '';
        break;
      case 'both':
        $vars['attachment_before'] .= $vars['pager'];
        break;
      default:
        // Already on the bottom.
    }
  }
}

I still think it would be a nice feature if the end user could control it, but in the meantime this is how a module can do it.

mandreato’s picture

Thanks for the suggestion !
I also think it would be great to have an option to set the pager on the top or on the bottom of the view (in 6.x too).

quantos’s picture

Was this ever implemented guys? I'm looking to do the same thing and can't yet find an easy way, in my case, to place the pager above the paged items. I can probably do it with CSS but I'm surprised this isn't a standard feature.

In my specific use-case I want to create a series of paged (Views) casestudies where each page is deeper than the average viewport depth hence would prefer to have pagers at the top of the page.

Is there really no easily configurable way to do this? Any pointers appreciated.

Q.

stan turyn’s picture

quantos,

it's very easy to move/display the pager where you want - just place the relevant view template into your theme's templates folder and move/copy this code:

<?php if ($pager): ?>
  <?php print $pager; ?>
<?php endif; ?>

to the desired position.

(the template you want is display output views-view.tpl.php - in Views UI for the relevant view go to Advanced->Other->Theme:Information and copy the code from views-view.tpl.php into a new file, named as suggested in Theme:Information (next name after views-view.tpl.php), place that file in tempalets folder, make your changes and click 'rescan' at the bottom of Theme:Information)

monish_deb’s picture

I can submit a patch for providing a option like "Attachment position" for "Attachments". So for Pager there will be "Pager Position" with top,bottom,both choices (bottom as default). Will it be ok ?

Exploratus’s picture

I think this is a fabulous idea. Seems like a simple UI improvement and it provides a lot more flexibility. A lot of sites have pagers on top and bottom. For example, ecommerce sites.

monish_deb’s picture

StatusFileSize
new3.63 KB
new18 KB
new8.28 KB

I have provided a separate option under PAGER section as "Pager position" which is set to 'bottom' by default. Please check the snapshot and patch.

Thanks,
Monish

mikeker’s picture

Status: Active » Needs work

@monish_deb, great work on this! Thanks.

I would suggest putting the pager placement option into the "Pager options" dialog (what you get when you click the "1 item" in the screenshot above). The pager details could then say something like "Use pager: Full | Above and below | 1 item". Also since the pager placement is specific to the display and follows the default/override setting of the pager options, it would reduce confusion. (Since there is no "For All displays/This page" option on the pager placement dialog, a user could think they could only place the pager for all displays of a view rather than on a per-display basis).

I'm not sure I'm explaining myself very well -- I'll see if I can roll a patch later today.

(Also, FYI, when you post a patch, set the status to "Needs review". That'll tell the testbot to run automated tests against the patch and get the attention of the module maintainers when the tests pass.)

mikeker’s picture

Title: Move pager above the page » Allow more options (above/below/both) for pager placement

Retitled to reflect current options.

Also, this was mentioned as needed in D8's revamp of Views: #2022297: [META] Unified toolset for Views in core.

mikeker’s picture

Status: Needs work » Needs review

I'm not sure what idiot made the comment in #12, but they were way off! :) If I look at the "exposed form in block" as an example, this does not belong in the pager plugin.

Besides, the obvious place to add this would be in views_plugin_pager, but doing that makes for very convoluted code -- trust me, I just tried. (None of the subclasses, for example, call parent::summary_title() meaning we would have to add the location text to each Views pager plugin as well as any in contrib).

My only concern with this patch is the possible confusion between "position" and "location" when it comes to pagers. "Position" might be misinterpreted as the position of the pager (as in page 5 of 10) rather than it's "location" on a page. But that's mostly picking nits...

Status: Needs review » Needs work

The last submitted patch, 1210980.patch, failed testing.

monish_deb’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

Yes you are right it must be location rather than position to be reasonable in its usage. Sorry I overlooked the meaning before implementing it :( On the otherhand I have also tried to introduce the feature for all those basic views display by introducing it in views_plugin_pager but seems more complex. I have improvised my patch, also replaced 'position' with 'location'.

Status: Needs review » Needs work

The last submitted patch, 1210980.patch, failed testing.

damiankloip’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.57 KB

Firstly, if we are going to fix/action this, I think we should do this in 8.x first. We can then backport when we get consensus?

I think I actually like the idea of providing a container area plugin to render the pager. The patches above look OK but I think they add complexity/workarounds and logic that we shouldn't need. If we go with a patch like this, we then just worry about what else we change to accommodate for this new area plugin.

Here's an initial patch that just adds a really simple area plugin that renders the pager.

damiankloip’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.x-dev
Component: Code » views.module
Issue tags: +VDC
dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Pager.phpundefined
@@ -0,0 +1,34 @@
+      if ($this->view->display_handler->renderPager()) {
+        return $this->view->renderPager($this->view->exposed_raw_input);

I would love to overrule the renderPager method from the display plugin instead, to have all the power to the user.

For sure this does not allow people to just move it to the top, but at least it covers the usecase of having one both at the bottom and the top, so +1 even we said for a long long time that you actually should change the template.

chris pergantis’s picture

Posted by Stan Shevchuk on April 8, 2013 at 3:11am
quantos,

it's very easy to move/display the pager where you want - just place the relevant view template into your theme's templates folder and move/copy this code:

<?php if ($pager): ?>
  <?php print $pager; ?>
<?php endif; ?>

to the desired position.

(the template you want is display output views-view.tpl.php - in Views UI for the relevant view go to Advanced->Other->Theme:Information and copy the code from views-view.tpl.php into a new file, named as suggested in Theme:Information (next name after views-view.tpl.php), place that file in tempalets folder, make your changes and click 'rescan' at the bottom of Theme:Information)

There is most always a way by module and theme. This worked like a charm in D7. Thanks to post #8

damiankloip’s picture

Yes, we know we can just override templates to put the pager where we want :) This doesn't really do what we want to in this issue. Which is make the pager placement more flexible in configuration.

damiankloip’s picture

StatusFileSize
new3.87 KB
new4.76 KB

So I was thinking something like this, where we have an option to not render the pager... Thoughts?

mondrake’s picture

#23: this is very nice...

With this patch you get an additional 'Global' element, being the pager, and include it in the header and/or footer regions of the view.

Just have a few comments on the UX - I know, I know, that won't be easy to address, but pls let me moonwalk :)

  1. The flag (option) to exclude rendering the pager in the pager region is available when you select the pager in both header and footer regions. In case that you decide to have pager in both regions, then this option is repeated - you can enable the option in header and disable in footer. This may be confusing: which setting has the lead?
  2. You can not select the type of pager (full/mini), just take the one setup in the Pager settings. Ideally, you may want to have a different 'style' in header than in footer.
  3. There is a different way to select the pager in the header/footer region, than in the pager region. Again, ideally, it would be nice that the Pager region have the same possibilities to select elements to put in as the header/footer. For instance, in h/f regions I can put a summary of total pages or items, while in the pager not, only the pager itself.
jibran’s picture

23: 1210980-23.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 23: 1210980-23.patch, failed testing.

DrCord’s picture

Issue summary: View changes

I understand the need for better configuration, it would be great to have it in the UI. However the solution in #21 worked great for me in this situation.

dawehner’s picture

Does this help to make sites more mobile friendly?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikl’s picture

#28: I'd say so, at least.

mariocantor’s picture

Thanks # 8 and #21 works fine. is important to write solutions in detail. think as person who have a just basic concepts.. and explain where you can find the files to modify.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Yzmir Ramirez’s picture

Can this make it in 8.2.1? I'm looking at placing my pager above my Comment's field.

mikl’s picture

#33: Since 8.2.1 has already been released, no. It would at the very earliest go into the next release, but given that the patch currently breaks the tests (and thus needs more work before it can be merged), that is unlikely to happen, so don't hold your breath.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

websiteworkspace’s picture

A Views UI setting to to have the pager: above, below, or both, would be fantastic.

This is a very much a needed feature.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mrpauldriver’s picture

I would like to see this. Anyone else?

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.