theme_table

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/theme.inc, строка 761

Версии
5 – 6
theme_table($header, $rows, $attributes = array(), $caption = NULL)

Возвращает темизированную таблицу.

Пример заполнения $rows:

$rows = array(
  // Простая строка
  array(
    'Cell 1', 'Cell 2', 'Cell 3'
  ),
  // Строка с атрибутами; некоторые из ячеек этой строки также содержат атрибуты.
  array(
    'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => 'funky'
  )
);

Параметры

$header Массив, содержащий заголовок таблицы. Каждый элемент массива может быть как локализированной строкой, так и ассоциативным массивом с ключами:

  • 'data': Локализированный заголовок колонки.
  • 'field': Колонка таблицы в базе данных (обязательно, если для колонки включена сортировка).
  • 'sort': Порядок сортировки по-умолчанию — по возрастанию ('asc') или по убыванию ('desc').
  • Любые атрибуты HTML, такие как 'colspan'; они будут применены к «заголовочной» ячейке таблицы.

$rows Массив строк таблицы. Каждая строка может являеться массивом ячеек, или ассоциативным массивом с ключами:

  • 'data': массив ячеек
  • Любые атрибуты HTML, такие как 'colspan'; они будут применены к данной строке.

Каждая ячейка может задаваться либо строкой (содержимым ячейки), либо ассоциативным массивом со следующими ключами:

  • 'data': Строка, которую нужно отобразить в ячейке таблицы.
  • 'header': Является ли эта ячейка заголовком таблицы.
  • Произвольные атрибуты HTML, например, 'colspan'; они будут применены к данной ячейке.

$attributes Любые аттрибуты HTML, для применения к тегу <table>.

$caption Локализированная строка для использоватия в теге <caption>.

Возвращаемое значение

Представление таблицы в виде HTML.

Связанные темы

▾ 46 функции вызывают theme_table()

aggregator_view in modules/aggregator/aggregator.module
book_admin_overview in modules/book/book.module
Возвращает административный краткий обзор всех книг.
contact_admin_categories in modules/contact/contact.module
Categories/list tab.
filter_filter_tips in modules/filter/filter.module
Реализация hook_filter_tips().
forum_overview in modules/forum/forum.module
Returns an overview list of existing forums and containers
menu_overview_tree in modules/menu/menu.module
Present the menu tree, rendered along with links to edit menu items.
node_overview_types in modules/node/content_types.inc
Displays the content type admin overview page.
node_revision_overview in modules/node/node.module
Generate an overview table of older revisions of a node.
path_overview in modules/path/path.module
Return a listing of all defined URL aliases.
poll_votes in modules/poll/poll.module
Callback for the 'votes' tab for polls you can see other votes on
profile_admin_overview in modules/profile/profile.module
Menu callback; display a listing of all editable profile fields.
statistics_node_tracker in modules/statistics/statistics.module
statistics_recent_hits in modules/statistics/statistics.module
Menu callback; presents the 'recent hits' page.
statistics_top_pages in modules/statistics/statistics.module
Menu callback; presents the 'top pages' page.
statistics_top_referrers in modules/statistics/statistics.module
Menu callback; presents the 'referrer' page.
statistics_top_visitors in modules/statistics/statistics.module
Menu callback; presents the 'top visitors' page.
statistics_user_tracker in modules/statistics/statistics.module
taxonomy_overview_terms in modules/taxonomy/taxonomy.module
Display a tree of all the terms in a vocabulary, with options to edit each one.
taxonomy_overview_vocabularies in modules/taxonomy/taxonomy.module
List and manage vocabularies.
theme_aggregator_page_list in modules/aggregator/aggregator.module
theme_block_admin_display in modules/block/block.module
Theme main block administration form submission.
theme_book_admin_table in modules/book/book.module
theme_comment_admin_overview in modules/comment/comment.module
Темизирует форму комментирования администратора.
theme_filter_admin_order in modules/filter/filter.module
Темизирует форму конфигурации порядка фильтров.
theme_filter_admin_overview in modules/filter/filter.module
theme_forum_list in modules/forum/forum.module
Format the forum listing.
theme_forum_topic_list in modules/forum/forum.module
Format the topic listing.
theme_locale_admin_manage_screen in includes/locale.inc
Theme the locale admin manager form.
theme_node_admin_nodes in modules/node/node.module
Theme node administration overview.
theme_node_search_admin in modules/node/node.module
theme_system_modules in modules/system/system.module
Темизирует форму модулей.
theme_system_modules_uninstall in modules/system/system.module
Темизирует таблицу отключенных на данный момент модулей.
theme_system_themes in modules/system/system.module
theme_system_theme_select_form in modules/system/system.module
Темизирует форму выбора темы.
theme_upload_attachments in modules/upload/upload.module
Отображение прикрепленных файлов в виде таблицы.
theme_upload_form_current in modules/upload/upload.module
Темизирует список прикрепленных файлов (вложений).
theme_user_admin_account in modules/user/user.module
Theme user administration overview.
theme_user_admin_new_role in modules/user/user.module
theme_user_admin_perm in modules/user/user.module
Темизирует страницу управления разрешениями.
tracker_page in modules/tracker/tracker.module
Menu callback. Prints a listing of active nodes on the site.
user_admin_access in modules/user/user.module
Menu callback: list all access rules
watchdog_event in modules/watchdog/watchdog.module
Menu callback; displays details about a log message.
watchdog_overview in modules/watchdog/watchdog.module
Menu callback; displays a listing of log messages.
watchdog_top in modules/watchdog/watchdog.module
Menu callback; generic function to display a page of the most frequent watchdog events of a specified type.
_locale_string_seek in includes/locale.inc
Perform a string search and display results in a table
_system_sql in modules/system/system.module

Код

<?php
function theme_table($header, $rows, $attributes = array(), $caption = NULL) {
  $output = '<table'. drupal_attributes($attributes) .">\n";

  if (isset($caption)) {
    $output .= '<caption>'. $caption ."</caption>\n";
  }

  // Format the table header:
  if (count($header)) {
    $ts = tablesort_init($header);
    // HTML requires that the thead tag has tr tags in it follwed by tbody
    // tags. Using ternary operator to check and see if we have any rows.
    $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
    foreach ($header as $cell) {
      $cell = tablesort_header($cell, $header, $ts);
      $output .= _theme_table_cell($cell, TRUE);
    }
    // Using ternary operator to close the tags based on whether or not there are rows
    $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
  }

  // Format the table rows:
  if (count($rows)) {
    $output .= "<tbody>\n";
    $flip = array('even' => 'odd', 'odd' => 'even');
    $class = 'even';
    foreach ($rows as $number => $row) {
      $attributes = array();

      // Check if we're dealing with a simple or complex row
      if (isset($row['data'])) {
        foreach ($row as $key => $value) {
          if ($key == 'data') {
            $cells = $value;
          }
          else {
            $attributes[$key] = $value;
          }
        }
      }
      else {
        $cells = $row;
      }

      // Add odd/even class
      $class = $flip[$class];
      if (isset($attributes['class'])) {
        $attributes['class'] .= ' '. $class;
      }
      else {
        $attributes['class'] = $class;
      }

      // Build row
      $output .= ' <tr'. drupal_attributes($attributes) .'>';
      $i = 0;
      foreach ($cells as $cell) {
        $cell = tablesort_cell($cell, $header, $ts, $i++);
        $output .= _theme_table_cell($cell);
      }
      $output .= " </tr>\n";
    }
    $output .= "</tbody>\n";
  }

  $output .= "</table>\n";
  return $output;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему