I have a page with multiple elements and pager. They are both created in the same function. Next to this i have a search box, and after clicking "search", ajax callback calls this same function and creates elements with pager depending on search term. This is working fine.

The problem is that once i search something, the first page shows results regarding the search but next pages don't. Like the pager didn't update which next items should show?!

my code is similar to this:

function mymodule_page() {
// this will be filled with an array of our content
$build = array();

// basic select query
$select = db_select('node', 'n')
  ->fields('n', array('nid'))
  ->extend('PagerDefault') // this adds the pager

// execute the query
$nids = $select->execute()->fetchCol();

// do something to output your results here.
foreach ($nids as $nid) {
$content .= $nid;
// add the content
$build['content'] = array('#markup' => $content)

// Add the pager
$build['pager'] = array(
  '#theme' => 'pager',
  '#weight' => 5,

// return the renderable array
return $build;
  • Are you using ajax for pager also? – Jayendra Kainthola Sep 5 '13 at 8:43
  • no, i replace "system/ajax" with normal url becouse it is not working with ajax. at least by default. – gregab Sep 5 '13 at 8:45
  • OK.. Are you creating page using custom module or views? Could you share your code? If you are using ajax for searching and ajax for pager then you need to update your ajax for pager after searching. – Jayendra Kainthola Sep 5 '13 at 8:48
  • I am using custom module for rendering output. How can i update pager? I recreate it each time, i thought this would be enough. Number of pages change correctly. – gregab Sep 5 '13 at 8:56
  • What is functionality of the custom_search function? I am not getting "I recreate it each time". – Jayendra Kainthola Sep 5 '13 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.