zoukankan      html  css  js  c++  java
  • [Drupal] Drupal7 How to theme a table with pager.

    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! 

  • 相关阅读:
    sqlserver 批量删除所有表语句
    C# 中的委托和事件
    Oracle建立用户
    C# Linq获取两个List或数组的差集交集
    Linux下Redis安装与配置操作说明
    word缩印
    centos7上的postgresql10安装和配置
    numpy技巧
    发票二维码扫描增强_06_持续优化
    发票二维码扫描增强_05_构建目标二维码
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2041633.html
Copyright © 2011-2022 走看看