[Drupal] Drupal7 - How to theme a table with pager.
2011-05-09 22:14
441 查看
As we know, Drupal7 has changed a lot, and we have to be familiar with it.
Here is an example to theme a table with pager.
$output = '';
$header = array(
array(
'data'=>t('Title'),
'field'=>'n.title',
),
array(
'data' => '',
),
);
$query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort');
$query->fields('n', array('nid', 'title'));
$ua_alias = $query->leftJoin('users_act' ,'ua', '%alias.nid = n.nid');
$query->addField($ua_alias, 'uid', 'ua_uid');
$query->addField($ua_alias, 'status', 'ua_status');
$query->condition('n.type', 'activity');
$objects = $query->limit(50)
->orderByHeader($header)
->execute()
->fetchAll();
$rows = array();
foreach ($objects as $key=>$object) {
$row = array();
$nid = $object->nid;
$row[] = l(check_plain($object->title), 'node/'.$object->nid, array('attributes'=>array('target'=>'_blank')));
$row[] = '<a href="?nid='.$nid.'" title='.$object->title.' target="_blank">my link</a>';
$rows[] = $row;
}
$output .= theme('table', array('header'=>$header, 'rows'=>$rows, 'empty'=>t('No result found.')));
$output .= theme('pager');
return $output;
It is just an example, any details, please see in drupal.org
Have fun with Drupal7!
Here is an example to theme a table with pager.
$output = '';
$header = array(
array(
'data'=>t('Title'),
'field'=>'n.title',
),
array(
'data' => '',
),
);
$query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort');
$query->fields('n', array('nid', 'title'));
$ua_alias = $query->leftJoin('users_act' ,'ua', '%alias.nid = n.nid');
$query->addField($ua_alias, 'uid', 'ua_uid');
$query->addField($ua_alias, 'status', 'ua_status');
$query->condition('n.type', 'activity');
$objects = $query->limit(50)
->orderByHeader($header)
->execute()
->fetchAll();
$rows = array();
foreach ($objects as $key=>$object) {
$row = array();
$nid = $object->nid;
$row[] = l(check_plain($object->title), 'node/'.$object->nid, array('attributes'=>array('target'=>'_blank')));
$row[] = '<a href="?nid='.$nid.'" title='.$object->title.' target="_blank">my link</a>';
$rows[] = $row;
}
$output .= theme('table', array('header'=>$header, 'rows'=>$rows, 'empty'=>t('No result found.')));
$output .= theme('pager');
return $output;
It is just an example, any details, please see in drupal.org
Have fun with Drupal7!
相关文章推荐
- how to deal with fdisk error: Re-reading the partition table failed with error 16: Device or resource busy.
- (转载)How to create a mobile WordPress theme with jQuery Mobile
- How to Share a Theme With All Users in a Windows 7 Computer?
- How To Use the PivotTable Office Web Component with VB (转载自微软)
- How can I set the background of UITableView (the tableview style is "Grouped") to use an image?
- How to find the correct version of JDeveloper to use with eBusiness Suite 11i or Release 12.x
- How to identify all the Corrupted Objects in the Database reported with RMAN
- [转自codeforces] How to come up with the solutions: techniques
- Tip/Trick: How to Run a Root “/” Site with the Local Web Server using VS 2005 SP1
- We need the sql script to query the table Ditronics.Kiosk.Journal to find journal with mismatch denom information versus amount.
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android问题一:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- How to get the field descriptions of a table
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- How to Change Default Grub Theme or Splash Image in Ubuntu 10.10
- How to join (ap invoice distributions all) AP table info with PO Table
- how to deal with the situation that the language support option disappears in linux ubuntu
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- [Drupal] Editing How to modify the CCK date field, set its to-date to null