Last active
December 18, 2015 06:39
-
-
Save alechko/5741295 to your computer and use it in GitHub Desktop.
Drupal table render example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Table header | |
$header = array( | |
'fruit' => t('Fruit'), | |
'a' => t('Vitamin A'), | |
'b1' => t('Vitamin B1'), | |
'b2' => t('Vitamin B2'), | |
); | |
// Table rows | |
$rows = array( | |
// Row 1 | |
array( | |
'fruit' => t('Apple'), | |
'a' => '98 IU', | |
'b1' => '0.031 mg', | |
'b2' => '0.047 mg', | |
), | |
// Row 2 | |
array( | |
'fruit' => t('Banana'), | |
'a' => '76 IU', | |
'b1' => '0.037 mg', | |
'b2' => '0.086 mg', | |
), | |
// Row 3 | |
array( | |
'fruit' => t('Orange'), | |
'a' => '295 IU', | |
'b1' => '0.114 mg', | |
'b2' => '0.052 mg', | |
), | |
); | |
$build['form'] = drupal_get_form('my_form_function'); | |
$build['table'] = array( | |
'#theme' => 'table', | |
'#header' => $header, | |
'#rows' => $rows, | |
'#attributes' => array('id' => 'custom-id','style' => 'width:100%;', 'class' => array('custom-class')), | |
'#empty' => t('No data to display.'), | |
); | |
return $build; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment