2

I am using Rest Service and pull the data from another non drupal db.

I wrote custom module with two form elements and render that data (rest service call) and display using theme table.

I wrote $form['pager'] = array('#theme' => 'pager'); for pagination.

Pagination is working only for data which rendered using db query. In my condition it's not working.

How can I add pagination for my table.

 function myForm($form, &$form_state){
 pager_array_splice($final_data, 10);
foreach($final_data as $key => $value){
     $source=explode('=',$key);
     $options[]=array( 
        'Token_Source'=>$source[0],
        'Tokens'=>$value,           
     );
}


$form['pagerTop'] = array('#theme' => 'pager');
$form['entities'] = array(
  '#type' => 'tableselect',
  '#header' => $header,
  '#options' => $options,
  '#attributes' => array('class' => array('entity-sort-table viewTable tokensTable')),
  '#empty' => t('There are no Notification ....'),
);
$form['pagerBottom'] = array('#theme' => 'pager');  
return $form;   
}
function pager_array_splice($data, $limit = 9, $element = 0) {
print_r($data);
global $pager_page_array, $pager_total, $pager_total_items;
$page = isset($_GET['page']) ? $_GET['page'] : '';

// Convert comma-separated $page to an array, used by other functions.
$pager_page_array = explode(',', $page);

// We calculate the total of pages as ceil(items / limit).
 $pager_total_items[$element] = count($data);
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
 $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element],     ((int)$pager_total[$element]) - 1));
 return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
}

1 Answer 1

2
  $row = pager_array_splice($options, 10);


$form['pagerTop'] = array('#theme' => 'pager');
  $form['entities'] = array(
  '#options' => $row,
  );

please assign $row value in the theme table

1
  • Hey tx for ur reply... Thats great..
    – Manu
    Dec 17, 2014 at 12:27

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .