Using Drupal 8 I created a form to load data from a webservice with ajax below the form. Now i'm trying to add pagination to result, but the paginator is not been loaded, i'm doing something wrong?. I've tried to follow the guide from https://www.drupal.org/docs/7/creating-custom-modules/howtos/paging-non-sql-data but it's for Drupal 7. Thanks in advance.

Here's my code:

$response contains an array with data from webservice.

$total contains the record of results

//number of records per page
$num_per_page = 3;
//get current page
$current_page = pager_default_initialize($total, $num_per_page);
$chunks = array_chunk($response, $num_per_page);
$current_page_items = $chunks[$current_page];
foreach ($current_page_items as $i => $item) {
  $current_page_items[$i] = array(
    '#theme' => 'ajax_search',
    '#item' => $item,

// Generate the render array for our page
$render_array['page'] = array (
  '#theme' => 'item_list',
  '#items' => $current_page_items,
// Calls Drupal standard pager theme and set 5 page links on pager
$render_array['pager'] = array (
  '#theme' => 'pager',
  '#quantity' => 5,

$response = new AjaxResponse();
  new HtmlCommand(
return $response;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.