theme_fieldset

1 篇文章 / 0 new
author
theme_fieldset
function useFieldSet() {
    $edit_element = array(
        '#title' => t('資料編輯'),
        '#children' => t('這是包在 FieldSet 元素內的表格資料') . myTable02(),
        '#attributes' => array('class' => array('collapsible')), //初始開啟
    );
    $fieldset_edit = theme('fieldset', array('element' => $edit_element));
    $show_element = array(
        '#title' => t('標題顯示文字'),
        '#children' => t('內容顯示資訊'),
        '#attributes' => array('class' => array('collapsible', 'collapsed')), //初始關閉
    );
    $fieldset_show = theme('fieldset', array('element' => $show_element));
    drupal_add_library('system', 'drupal.collapse'); //需加入此 library 否則無法開閉動作
    return $fieldset_edit . $fieldset_show;
}
function myTable02() {
    $header = array(//標題
        array('data' => t('Title')),
        array('data' => '', 'style' => 'width: 70px'),// 增加屬性資料
    );
    $query = db_select('node', 'n')
            ->fields('n', array('nid', 'title'))
            ->execute()->fetchAll();
    foreach ($query as $record_edit_table) { //dataSet
        $rows[] = array(       
            array(//本文連結
                'data' => l($record_edit_table->title, 'node/' . $record_edit_table->nid, array('attributes'=>array('target'=>'_blank')) ),
            ),
            array(//編輯
                'data' => l(t('edit'), 'node/' . $record_edit_table->nid . '/edit') . ' / ' . l(t('delete'), 'node/' . $record_edit_table->nid . '/delete'),
            ),
        );
    }
    $editTable = theme('table', array(
            'header' => $header, // 欄位標題
            'rows' => $rows, //資料集
            'caption' => t('資料編輯表格'), //表格抬頭標題
            //'attributes' => array('style' => 'width: 80%'),
        )
    );
    return $editTable;
}
Free Web Hosting