当前位置: 首页 > 工具软件 > tablePager > 使用案例 >

[Drupal] Drupal7 - How to theme a table with pager.

关浩壤
2023-12-01

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! 

 类似资料: