Monday 2 July 2012

Drupal 7 theme table creation with pagination & sorting


$header = array(array(‘data’=>t(‘Module’),’field’=>’module’,'sort’=>’asc’), t(‘Delta’), t(‘Theme’));

$sql_query = db_select(‘block’, ‘s’);

$sql_query->fields(‘s’, array(‘module’, ‘delta’, ‘theme’));
$sql_query = $sql_query->extend(‘TableSort’)->extend(‘PagerDefault’)->limit(5);
$result = $sql_query->orderByHeader($header)->execute();

foreach($result as $res){
$rows[] = array($res->module,$res->delta,$res->theme);
}

$output = theme(‘table’, array(‘header’ => $header, ‘rows’ => $rows, ‘attributes’ => array(‘id’ => ‘my-module-table’)));
$output .= theme(‘pager’);

print $output;

2 comments:

  1. wow...really nice code. i just apply in my demo site and it's really working. i think people should go through it. Thank you.

    Drupal Web Development

    ReplyDelete
  2. Welcome Allricjohnson..... if you have any question so you can tell me regarding drupal6 and drupal7 :)

    ReplyDelete