Friday 25 May 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;
?>

No comments:

Post a Comment