You are here

Drupal 7 And Pager Elements


While working on updating my client support system to Drupal 7, I encountered an interesting problem. In the page to view tickets, I have a pager query running, utilizing the new Drupal database layer. The only problem was my pager wasn't showing. I started poking around and found a view in a block that has a mini-pager. That was causing my pages theme_pager to return the wrong element. There was one of two fixes I could take for this. The first being to utilize the pager configuration settings in Views:

The other option is to specify the element ID in my custom module's query. For the new database system in Drupal, it looks somethng like this:

{syntaxhighlighter brush:php} $query = db_select('hit_tickets', 't')->extend('PagerDefault')->extend('TableSort')->element(4); {/syntaxhighlighter}

Then to return the information in your page's build array:

{syntaxhighlighter brush:php} $build['pager'] = array( '#theme' => 'pager', '#weight' => 5, '#element' => 4 ); {/syntaxhighlighter}

Of course there is a final solution - set the element ID in both items. I ended up going with this route just for safety. One thing to note when adding more elements is that the page query string becomes longer. Basically your URL will add a coma for each ID, so with an element ID of 4, the pager query looks like this:


So it's best to avoid multiple pagers per page if possible. Rethinking the design of my new ticketing/support system, I'm probably going to do just that.